简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM