Django 1.8 creates migration but nothing has changed

大城市里の小女人 提交于 2019-12-11 12:38:30

问题


I am having a migration issue with a Django 1.8.2 application. I'm using two models, Product and Fee. Product recently had a change to its unique_together field. Fee had no changes to its unique_together field. When I run ./manage.py makemigrations I get a file with two changes:

operations = [
    migrations.AlterUniqueTogether(
        name='fee',
        unique_together=set([('product', 'fee_type', 'content_type', 'object_id', 'activation_date')]),
    ),
    migrations.AlterUniqueTogether(
        name='product',
        unique_together=set([('producer', 'product_type', 'term')]),
    ),
]

You'll notice it is changing the unique together constraint for Product, which is fine. But then it is also doing it for Fee. That causes and error because that unique together constraint already exists in the database. The error is django.db.utils.ProgrammingError: relation "product_fee_product_id_7b033c697cde4424_uniq" already exists

Every time I run ./manage.py makemigrations I get the AlterUniqueTogether stuff for the Fee model, even if I simply comment it out or remove it from the file with both migrations. How can I prevent makemigrations from detecting this nonexistent change?


回答1:


You could try creating a migration that only alters the unique together for the Fee model, and then use the --fake option to apply it

./manage.py migrate yourapp 00XX_your_migration --fake

After you've faked the migration, the change should not be included in any new migrations you create.



来源:https://stackoverflow.com/questions/30376534/django-1-8-creates-migration-but-nothing-has-changed

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