#31255: Migrations create a redundant RemoveField operation when deleting 2
models
with related fields.
-------------------------------------+-------------------------------------
Reporter: Panagis | Owner: Rohit Jha
Alisandratos |
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration,optimizer | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
This is explained in more details in the above links but the crux of the
issue is that `RemoveField` and `DeleteModel` operations don't hold a
reference to ''what'' they are removing so
[https://github.com/django/django/blob/e65fea9292ffdeb9bb76062f6cb2a5ff514ae969/django/db/migrations/operations/models.py#L268-L271
they must assume they could be referring to any model].
In other words, because the `DeleteModel` operation doesn't hold a
reference to the model state it's removing it cannot differentiate between
the cases where the optimization can be performed (this ticket's example)
and when it cannot because there's cycles between models (comment:6).
You likely can get the optimization working for this ticket by changing
`DeleteModel.references_model` to return `False` but
[https://github.com/django/django/blob/e65fea9292ffdeb9bb76062f6cb2a5ff514ae969/tests/migrations/test_autodetector.py#L2029-L2040
that I'll break when for the cases where model cycles are deleted in the
same migration].
If `DeleteModel` operations were created with the set of fields they have
at removal time it would be possible for them to properly determine
whether or not they references each other.
--
Ticket URL: <https://code.djangoproject.com/ticket/31255#comment:12>
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/066.db849099ec188c3409a3d9c3ede34a5e%40djangoproject.com.