MCPcopy
hub / github.com/django/django / test_create_model_db_on_delete

Method test_create_model_db_on_delete

tests/schema/tests.py:644–664  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

642 @isolate_apps("schema")
643 @skipUnlessDBFeature("supports_foreign_keys", "can_introspect_foreign_keys")
644 def test_create_model_db_on_delete(self):
645 class Parent(Model):
646 class Meta:
647 app_label = "schema"
648
649 class Child(Model):
650 parent_fk = ForeignKey(Parent, DB_SET_NULL, null=True)
651
652 class Meta:
653 app_label = "schema"
654
655 with connection.schema_editor() as editor:
656 editor.create_model(Parent)
657 with CaptureQueriesContext(connection) as ctx:
658 with connection.schema_editor() as editor:
659 editor.create_model(Child)
660
661 self.assertForeignKeyNotExists(Child, "parent_id", "schema_parent")
662 self.assertIs(
663 any("ON DELETE" in query["sql"] for query in ctx.captured_queries), True
664 )
665
666 @isolate_apps("schema")
667 def test_no_db_constraint_added_during_primary_key_change(self):

Callers

nothing calls this directly

Calls 4

schema_editorMethod · 0.80
create_modelMethod · 0.45

Tested by

no test coverage detected