#27731: Squashmigrations doesn't optimize AlterField related_name across
AlterUniqueTogether/AlterIndexTogether
-------------------------------------+-------------------------------------
Reporter: Ed Morley | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: | Version: master
Migrations |
Severity: Normal | Keywords: squashmigrations
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `squashmigrations` command doesn't combine an `AlterField()` with
`CreateModel()` in the case below, when all that was changed was the
`related_name`.
ie: This fails on Django master...
{{{
diff --git a/tests/migrations/test_optimizer.py
b/tests/migrations/test_optimizer.py
index fc4f0ac..93a43a7 100644
--- a/tests/migrations/test_optimizer.py
+++ b/tests/migrations/test_optimizer.py
@@ -572,6 +572,26 @@ class OptimizerTests(SimpleTestCase):
],
)
+ self.assertOptimizesTo(
+ [
+ migrations.CreateModel("Bar", [("name",
models.CharField(max_length=255))]),
+ migrations.CreateModel("Foo", [
+ ("a", models.ForeignKey("testapp.Bar", models.CASCADE)),
+ ("b", models.IntegerField()),
+ ]),
+ alter,
+ migrations.AlterField("Foo", "a",
models.ForeignKey("testapp.Bar", models.CASCADE, related_name="baz")),
+ ],
+ [
+ migrations.CreateModel("Bar", [("name",
models.CharField(max_length=255))]),
+ migrations.CreateModel("Foo", [
+ ("a", models.ForeignKey("testapp.Bar", models.CASCADE,
related_name="baz")),
+ ("b", models.IntegerField()),
+ ]),
+ alter,
+ ],
+ )
+
# RenameField
self.assertDoesNotOptimize(
[
}}}
This causes failures in:
* test_create_alter_index_field
* test_create_alter_unique_field
ie optimization should occur but doesn't, when `alter` is:
`migrations.AlterUniqueTogether("Foo", [["a", "b"]])`
...or when `alter` is:
`migrations.AlterIndexTogether("Foo", [["a", "b"]])`
(But passes in the `AlterOrderWithRespectTo` case).
--
Ticket URL: <https://code.djangoproject.com/ticket/27731>
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/051.d22f6cdf59be09dbab31db27c18cabdf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.