Kaydet (Commit) 8e8c0792 authored tarafından Simon Charette's avatar Simon Charette Kaydeden (comit) Tim Graham

Refs #18081 -- Asserted db constraints are created for fk to proxy models.

üst de314231
...@@ -177,6 +177,36 @@ class SchemaTests(TransactionTestCase): ...@@ -177,6 +177,36 @@ class SchemaTests(TransactionTestCase):
else: else:
self.fail("No FK constraint for author_id found") 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') @skipUnlessDBFeature('supports_foreign_keys')
def test_fk_db_constraint(self): def test_fk_db_constraint(self):
"Tests that the db_constraint parameter is respected" "Tests that the db_constraint parameter is respected"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment