summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2015-08-08 11:52:39 -0400
committerTim Graham <timograham@gmail.com>2015-09-23 14:59:05 -0400
commit8e8c0792c07f6dfbee5115d29911191adee04f2e (patch)
treef8a6c35efd7b7386fa1e45d84e90eb6af971b80d /tests
parentde31423130912a012513aad93ec805f8e08a0d5e (diff)
Refs #18081 -- Asserted db constraints are created for fk to proxy models.
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 9e0731cf4f..3c7bf96605 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -178,6 +178,36 @@ class SchemaTests(TransactionTestCase):
self.fail("No FK constraint for author_id found")
@skipUnlessDBFeature('supports_foreign_keys')
+ def test_fk_to_proxy(self):
+ "Tests that creating a FK to a proxy model creates database constraints."
+ class AuthorProxy(Author):
+ class Meta:
+ app_label = 'schema'
+ apps = new_apps
+ proxy = True
+
+ class AuthorRef(Model):
+ author = ForeignKey(AuthorProxy, on_delete=CASCADE)
+
+ class Meta:
+ app_label = 'schema'
+ apps = new_apps
+
+ self.local_models = [AuthorProxy, AuthorRef]
+
+ # Create the table
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(AuthorRef)
+ constraints = self.get_constraints(AuthorRef._meta.db_table)
+ for details in constraints.values():
+ if details['columns'] == ['author_id'] and details['foreign_key']:
+ self.assertEqual(details['foreign_key'], ('schema_author', 'id'))
+ break
+ else:
+ self.fail('No FK constraint for author_id found')
+
+ @skipUnlessDBFeature('supports_foreign_keys')
def test_fk_db_constraint(self):
"Tests that the db_constraint parameter is respected"
# Create the table