1

I'm trying to migrate my Django project from using sqlite3 to using PostgreSQL. I've created the database for the project, but when I try to run syncdb, I get the following error:

django.db.utils.ProgrammingError: column "partial_value" cannot be cast automatically to type double precision
HINT: Specify a USING expression to perform the conversion.

The column is defined like this in the model:

partial_value = models.FloatField()

I tried searching for similar questions, but they seemed to be more about replacing field types.

2 Answers 2

1

You needs to update the type of column for 'partial_value' column. Place name of table in following code for table_name

ALTER TABLE table_name ALTER COLUMN partial_value TYPE double precision USING (trim(partial_value)::double precision);
Sign up to request clarification or add additional context in comments.

3 Comments

Could you explain why the error happens in the first place? I checked the type of the column and it was of type 'character varying' instead of double precision.
As you said the earlier column type was character , but now it seems it is float type, so the data type of the partial_value is changed by dajngo, But that change is not reflected into the database, that's why error is coming.
No, the column type has always been FloatField in Django. The type in PostgreSQL database was 'character varying'. This is the thing I'm wondering: why does the FloatField convert to 'character varying' ?
0

I found the reason to why the field was applied as character varying in the first place. It turns out there was a migration file that defined it that way. The error was fixed by removing the migration file and running manage.py syncdb.

1 Comment

see also : stackoverflow.com/questions/30948392/… if you need a less specific answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.