In my Django model I had a field like this one (simplified):
category = models.ForeignKey(EnumValue, to_field='code', related_name='+', verbose_name="Kategorie", db_column='Kategorie')
Then I removed the to_field argument to convert the foreign key back to one that points to the primary key.
Django migration produced just a simple AlterField for this change and seems not to modify the foreign key or translate existing data correctly. Anyways, I get this error message, when applying the migration:
pymysql.err.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails
I cannot find anything about this specific case in the web. I would say this is a Django migration bug. Do you agree? Do you know a workaround for this?
The following worked for me:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With