Why does django 1.7 creates migrations for changes in field choices?

雨燕双飞 提交于 2019-12-03 23:47:16

问题


I have observed this behaviour on version 1.7 but not in previous versions using south migration.

eg.

class RedemptionCode(models.Model):
    EXPIRE_OPTIONS = (
        ('1 week', '1 Week'),
    )

    expire_option = models.CharField(max_length=255, choices=EXPIRE_OPTIONS)

when I added more options:

EXPIRE_OPTIONS = (
    ('1 week', '1 Week'),
    ('2 weeks', '2 Weeks'),
    ('1 month', '1 Month'),
    ('1 day', '1 Day'),
)

and run makemigrations, it creates a migration for it, coming from south background I thought it should say no changes detected as it doesn't affects database schema. I don't know what purpose it serves:

class Migration(migrations.Migration):

    dependencies = [
        ('credits', '0001_initial'),
    ]

    operations = [
        migrations.AlterField(
            model_name='redemptioncode',
            name='expire_option',
            field=models.CharField(max_length=255, choices=[('1 week', '1 Week'), ('2 weeks', '2 Weeks'), ('1 month', '1 Month'), ('1 day', '1 Day')]),
        ),
    ]

回答1:


After raised the ticket and got closed due to duplication, finally found the answer:

This is by design. There are several reasons, not least of which for me that datamigrations at points in history need to have a full accurate representation of the models, including all their options not just those which affect the database.

Reference:

  • https://code.djangoproject.com/ticket/22837
  • https://code.djangoproject.com/ticket/23581


来源:https://stackoverflow.com/questions/26152633/why-does-django-1-7-creates-migrations-for-changes-in-field-choices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!