#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.9
     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
-------------------------------------+-------------------------------------
Changes (by Markus Holtermann):

 * version:  1.8 => 1.9


Comment:

 A good find, Artem. Thank you!

 The issue seems to come from e470f311d654267ec86f9a6325ec500345b9dff2
 which is part of 1.9 release cycle, but not 1.8.

 While the docstring on
 
https://github.com/django/django/commit/e470f311d654267ec86f9a6325ec500345b9dff2
 #diff-c11e6432df7086eda3dfb9ab8e5b2839R1141 is clearly wrong, the test
 itself is still correct because the `RemoveField` operation doesn't touch
 any of the fields referred to in `AlterUniqueTogether` or
 `AlterIndexTogether`.

 There is a
 
[https://github.com/MarkusH/django/blob/8e352876c337332b45a72da8bbccad2830c7b1e0/tests/migrations/test_optimizer.py#L603-L632
 test for the migration optimizer] that shows a RemoveField operation after
 the *Together operation is not moved to the front if both involve the same
 field.

 Adding this code though will make the test fail:
 {{{#!python
         self.assertOptimizesTo(
             [
                 migrations.CreateModel("Foo", [
                     ("a", models.IntegerField()),
                     ("b", models.IntegerField()),
                 ]),
                 migrations.RemoveField("Foo", "b"),
                 alter,
             ],
             [
                 migrations.CreateModel("Foo", [
                     ("a", models.IntegerField()),
                     ("b", models.IntegerField()),
                 ]),
                 alter,
                 migrations.RemoveField("Foo", "b"),
             ],
         )
 }}}
 which I believe is what you're experiencing. Maybe even this would be an
 expected behavior:
 {{{#!python

         self.assertOptimizesTo(
             [
                 migrations.CreateModel("Foo", [
                     ("a", models.IntegerField()),
                     ("b", models.IntegerField()),
                 ]),
                 migrations.RemoveField("Foo", "b"),
                 alter,
             ],
             [
                 migrations.CreateModel("Foo", [
                     ("a", models.IntegerField()),
                 ]),
             ],
         )
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28862#comment:8>
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.d1fd0c5a99ddfd72c48cec18a6002ed5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to