MCPcopy
hub / github.com/django/django / test_fk_to_proxy

Method test_fk_to_proxy

tests/schema/tests.py:549–571  ·  view source on GitHub ↗

Creating a FK to a proxy model creates database constraints.

(self)

Source from the content-addressed store, hash-verified

547
548 @skipUnlessDBFeature("supports_foreign_keys")
549 def test_fk_to_proxy(self):
550 "Creating a FK to a proxy model creates database constraints."
551
552 class AuthorProxy(Author):
553 class Meta:
554 app_label = "schema"
555 apps = new_apps
556 proxy = True
557
558 class AuthorRef(Model):
559 author = ForeignKey(AuthorProxy, on_delete=CASCADE)
560
561 class Meta:
562 app_label = "schema"
563 apps = new_apps
564
565 self.local_models = [AuthorProxy, AuthorRef]
566
567 # Create the table
568 with connection.schema_editor() as editor:
569 editor.create_model(Author)
570 editor.create_model(AuthorRef)
571 self.assertForeignKeyExists(AuthorRef, "author_id", "schema_author")
572
573 @skipUnlessDBFeature("supports_foreign_keys", "can_introspect_foreign_keys")
574 def test_fk_db_constraint(self):

Callers

nothing calls this directly

Calls 3

schema_editorMethod · 0.80
create_modelMethod · 0.45

Tested by

no test coverage detected