Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

South ignores change in field default value in Python / Django

Why does South not recognize changes in default field values in Python models? For example, take this existing model that is migrated with south:

class MyFamily(models.Model):
    family_size = models.IntegerField(verbose_name="What is your family size?", default=2)

Now, I'd like to change the default value from two to four. However, when schemamigrating the module, South reports:

python manage.py schemamigration family --auto change_default_from_two_to_four_for_size

Running migrations for family:
- Nothing to migrate.
    - Loading initial data for family.

I could manually update the initial migration, and use the SQL to directly update the field, but that's a pain. Is there a South command I haven't found that recognizes the change in the default?

Thanks!

like image 769
MontyThreeCard Avatar asked May 16 '11 23:05

MontyThreeCard


1 Answers

South won't update the default value for existing columns, because it matters for him only when adding a new column to a non empty table. The django orm will handle writing the new default value to new rows before hitting the database.

If you will work on the database from outside django orm, you have to update it manually.

More explanations south/db.add_column

like image 115
manji Avatar answered Nov 02 '22 12:11

manji