summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2014-12-11 17:52:42 +0100
committerTim Graham <timograham@gmail.com>2014-12-11 13:28:21 -0500
commit44927ba817a4ecf9834d429ff6c86bc5ac961305 (patch)
tree5eadbb9c6799590df9ef33cc5f13ced5f58a5181
parent38fc463fbfb9b74c38f1e8c33e4c99bc2274a880 (diff)
Fixed #23956 -- Fixed migration creation for multiple table inheritance
-rw-r--r--django/db/migrations/autodetector.py2
-rw-r--r--docs/releases/1.7.2.txt4
-rw-r--r--tests/migrations/test_autodetector.py23
3 files changed, 28 insertions, 1 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index eab34454a2..007ea33666 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -463,7 +463,7 @@ class MigrationAutodetector(object):
if field.rel.to:
if field.primary_key:
primary_key_rel = field.rel.to
- else:
+ elif not field.rel.parent_link:
related_fields[field.name] = field
# through will be none on M2Ms on swapped-out models;
# we can treat lack of through as auto_created=True, though.
diff --git a/docs/releases/1.7.2.txt b/docs/releases/1.7.2.txt
index 884a5970b1..6a98d43419 100644
--- a/docs/releases/1.7.2.txt
+++ b/docs/releases/1.7.2.txt
@@ -115,3 +115,7 @@ Bugfixes
* Fixed index creation by the migration infrastructure, particularly when
dealing with PostgreSQL specific {text|varchar}_pattern_ops indexes
(:ticket:`23954`).
+
+* Fixed bug in ``makemigrations`` that created broken migration files when
+ dealing with multiple table inheritance and inheriting from more than one
+ model (:ticket:`23956`).
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 8733b8453f..9e7511cc45 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1446,6 +1446,29 @@ class AutodetectorTests(TestCase):
self.assertOperationAttributes(changes, 'testapp', 0, 0, name="Author")
self.assertOperationAttributes(changes, 'testapp', 0, 1, name="Aardvark")
+ def test_multiple_bases(self):
+ """#23956 - Tests that inheriting models doesn't move *_ptr fields into AddField operations."""
+ A = ModelState("app", "A", [("a_id", models.AutoField(primary_key=True))])
+ B = ModelState("app", "B", [("b_id", models.AutoField(primary_key=True))])
+ C = ModelState("app", "C", [], bases=("app.A", "app.B"))
+ D = ModelState("app", "D", [], bases=("app.A", "app.B"))
+ E = ModelState("app", "E", [], bases=("app.A", "app.B"))
+ # Make state
+ before = self.make_project_state([])
+ after = self.make_project_state([A, B, C, D, E])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number/type of migrations?
+ self.assertNumberMigrations(changes, "app", 1)
+ self.assertOperationTypes(changes, "app", 0, [
+ "CreateModel", "CreateModel", "CreateModel", "CreateModel", "CreateModel"
+ ])
+ self.assertOperationAttributes(changes, "app", 0, 0, name="A")
+ self.assertOperationAttributes(changes, "app", 0, 1, name="B")
+ self.assertOperationAttributes(changes, "app", 0, 2, name="C")
+ self.assertOperationAttributes(changes, "app", 0, 3, name="D")
+ self.assertOperationAttributes(changes, "app", 0, 4, name="E")
+
def test_proxy_bases_first(self):
"""Tests that bases of proxies come first."""
# Make state