问题
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