#28862: Removing a field from index_together/unique_together and from the model
generates a migration that crashes
-------------------------------------+-------------------------------------
Reporter: Artem Maslovskiy | Owner: Ramiro
| Morales
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: models migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Ramiro Morales):
This is what I've found so far:
It seems the optimization introduced in
e470f311d654267ec86f9a6325ec500345b9dff2 (later refactored in
49f4c9f4c61885189d136d7073c26ecc91b482b1) by which a sequence of schema
migrations operations like this:
{{{
- AlterIndexTogether(index_together=['title', 'author', 'newfield'] ->
index_together=['title', 'author'])
- RemoveField('newfield')
}}}
gets swapped to
{{{
- RemoveField('newfield')
- AlterIndexTogether(index_together=['title', 'author', 'newfield'] ->
index_together=['title', 'author'])
}}}
This is because the `references_field()` method of
`django.db.migrations.operations.AlterIndexTogether` considers only the
final set of `index_together` fields to conclude there is no overlap in
field affected by the two operations. This reasoning might be valid when
reordering operation sequences which involve e.g. `AddField` But when
it's interacting with `RemoveField` (and `RenameField`?) it needs to
consider the _initial_ set of `index_together` fields instead.
if it did, then it would discover it can't optimize the
`AlterIndexTogether` to be after the `RemoveField` whcih is that the OP
reports.
Example is for `Meta.index_together` but affects also al least
`Meta.unique_together` too. AFAICT fixing this might involve some non-
trivial refactoring.
I'm open to confirmation/rebuttal and to ideas on how this could be
solved.
--
Ticket URL: <https://code.djangoproject.com/ticket/28862#comment:6>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.3b539fa8c6d28e4554133f236f926bb8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.