Sunday, September 8, 2013

south migration on heroku does not request default value

south migration on heroku does not request default value

While running a Django South migration on Heroku I received the following
error
Running `python my_proj/manage.py migrate my_app` attached to terminal...
up, run.7574
Running migrations for my_app:
- Migrating forwards to 0056_auto__chg_field_mymodel_myfield.
> my_app:0056_auto__chg_field_mymodel_myfield
FATAL ERROR - The following SQL query failed: ALTER TABLE "my_app_mymodel"
ALTER COLUMN "myfield" TYPE double precision, ALTER COLUMN "myfield" SET
NOT NULL, ALTER COLUMN "myfield" DROP DEFAULT;
The error was: column "myfield" contains null values
Error in migration: my_app:0056_auto__chg_field_mymodel_myfield
Traceback (most recent call last):
File "my_proj/manage.py", line 18, in <module>
execute_manager(settings)
File
"/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py",
line 459, in execute_manager
utility.execute()
# omitted many uninteresting lines here....
File
"/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py",
line 52, in execute
return self.cursor.execute(query, args)
django.db.utils.IntegrityError: column "myfield" contains null values
This occurred even though I specified 0.0 as a default value for this
FloatField.
Also, even if I haven't, south was supposed to ask interactively for a
default value, which it didn't (would that interactive interface work
through Heroku's toolbelt?).
I can of course delete the migration and create two migrations:

update all nulls to 0.0
alter the field to be not-nullable
but that would be a workaround to a flow that should work, and would open
a race where objects could be saved with null between the two
migrations...
What's wrong here and how can I fix it?

No comments:

Post a Comment