summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-07-16 09:59:08 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-07-16 09:59:37 -0700
commitde709001c45c6646ecf39689949e3011ae5be197 (patch)
treecb0b0b6cdb1008ab80f0e71236c03760a5584e4b
parent8e34bcdfba16cb1dc3096da57d1e82d3839472a8 (diff)
[1.7.x] Fixed #23041: Bad base dependencies for proxy models
-rw-r--r--django/db/migrations/autodetector.py2
-rw-r--r--tests/migrations/test_autodetector.py19
2 files changed, 19 insertions, 2 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index 6f7f446c84..4fd2246a4a 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -560,7 +560,7 @@ class MigrationAutodetector(object):
for base in model_state.bases:
if isinstance(base, six.string_types) and "." in base:
base_app_label, base_name = base.split(".", 1)
- dependencies.append((base_app_label, base_name, None, False))
+ dependencies.append((base_app_label, base_name, None, True))
# Generate creation operation
self.add_operation(
app_label,
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index f6b88030d5..9975087cb4 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -40,6 +40,7 @@ class AutodetectorTests(TestCase):
author_proxy_options = ModelState("testapp", "AuthorProxy", [], {"proxy": True, "verbose_name": "Super Author"}, ("testapp.author", ))
author_proxy_notproxy = ModelState("testapp", "AuthorProxy", [], {}, ("testapp.author", ))
author_proxy_third = ModelState("thirdapp", "AuthorProxy", [], {"proxy": True}, ("testapp.author", ))
+ author_proxy_proxy = ModelState("testapp", "AAuthorProxyProxy", [], {"proxy": True}, ("testapp.authorproxy", ))
author_unmanaged = ModelState("testapp", "AuthorUnmanaged", [], {"managed": False}, ("testapp.author", ))
author_unmanaged_managed = ModelState("testapp", "AuthorUnmanaged", [], {}, ("testapp.author", ))
author_with_m2m = ModelState("testapp", "Author", [
@@ -993,6 +994,22 @@ class AutodetectorTests(TestCase):
self.assertOperationAttributes(changes, 'testapp', 0, 0, name="Author")
self.assertOperationAttributes(changes, 'testapp', 0, 1, name="Aardvark")
+ def test_proxy_bases_first(self):
+ """
+ Tests that bases of proxies come first.
+ """
+ # Make state
+ before = self.make_project_state([])
+ after = self.make_project_state([self.author_empty, self.author_proxy, self.author_proxy_proxy])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number of migrations?
+ self.assertNumberMigrations(changes, 'testapp', 1)
+ self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel", "CreateModel", "CreateModel"])
+ self.assertOperationAttributes(changes, 'testapp', 0, 0, name="Author")
+ self.assertOperationAttributes(changes, 'testapp', 0, 1, name="AuthorProxy")
+ self.assertOperationAttributes(changes, 'testapp', 0, 2, name="AAuthorProxyProxy")
+
def test_pk_fk_included(self):
"""
Tests that a relation used as the primary key is kept as part of CreateModel.
@@ -1030,7 +1047,7 @@ class AutodetectorTests(TestCase):
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_last_dependency(self):
"""
- Tests that a dependency to an app with existing migrations uses __last__.
+ Tests that a dependency to an app with existing migrations uses __latest__.
"""
# Load graph
loader = MigrationLoader(connection)