#30966: Migration crashes due to foreign key issue, depending on otherwise
irrelevant order on MySQL.
-------------------------------------+-------------------------------------
Reporter: Peter Thomassen | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration mySQL | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Markus Holtermann):
As already suspected by Simon, this is indeed related to Django not
reloading related models when non-relational fields change.
I see a few ways forward within the migration system, with various pros
and cons
1. Reload all related models, regardless if the changed field is a
relational field or referenced by a relational field. This will come with
a huge run-time penalty that the delaying brought
1. Try to catch these kind of database error or do some Python-level
checking beforehand (`assert model1 is
model2._meta.get_field("foo").related_model`). If we run into any issue
there, reload all related models. Depending on how expensive that is, we
could possibly do that after each migration operation and make the delayed
model reloading based on that.
1. Reload all models after each migrations is applied when the
`ProjectState.is_delayed is False`. That would bring the benefit that it
doesn't matter if one applies migrations individually or in a batch.
1. Leave as-is; the first migration can be optimized anyway
I haven't completely made up my mind about the "best" approach here. But
ideally we'd get rid of model classes in migrations and solely work off of
the `ModelState`. My last attempt got stuck do to the backwards
compatibility in the `SchemaEditor`.
--
Ticket URL: <https://code.djangoproject.com/ticket/30966#comment:13>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.1ca552449acab25e0233f0fc6ac1a0a6%40djangoproject.com.