summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2017-01-30 14:14:38 -0500
committerTim Graham <timograham@gmail.com>2018-07-10 16:47:57 -0400
commite4c0878b30cf1fc29212185c55614fc463393af1 (patch)
tree347394b30f8224a42e50e4d880d2446fcda49500
parent263e03941187f4ffdd09b7e7ecee442717064083 (diff)
Refs #22875 -- Fixed an optimizer test to use a valid scenario.
An explicit intermediary many-to-many relationship must declare forward and reverse foreign keys. The original issue was in the autodetector as these operations shouldn't have been generated in this order in the first place which is tested by AutodetectorTests.test_create_with_through_model.
-rw-r--r--tests/migrations/test_optimizer.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/tests/migrations/test_optimizer.py b/tests/migrations/test_optimizer.py
index 0a13ef290f..7a1876a508 100644
--- a/tests/migrations/test_optimizer.py
+++ b/tests/migrations/test_optimizer.py
@@ -318,14 +318,18 @@ class OptimizerTests(SimpleTestCase):
AddField should NOT optimize into CreateModel if it's an M2M using a
through that's created between them.
"""
- # Note: The middle model is not actually a valid through model,
- # but that doesn't matter, as we never render it.
self.assertDoesNotOptimize(
[
- migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
- migrations.CreateModel("LinkThrough", []),
+ migrations.CreateModel('Employee', []),
+ migrations.CreateModel('Employer', []),
+ migrations.CreateModel('Employment', [
+ ('employee', models.ForeignKey('migrations.Employee', models.CASCADE)),
+ ('employment', models.ForeignKey('migrations.Employer', models.CASCADE)),
+ ]),
migrations.AddField(
- "Foo", "link", models.ManyToManyField("migrations.Link", through="migrations.LinkThrough")
+ 'Employer', 'employees', models.ManyToManyField(
+ 'migrations.Employee', through='migrations.Employment',
+ )
),
],
)