MCPcopy
hub / github.com/django/django / test_alter_fk_checks_deferred_constraints

Method test_alter_fk_checks_deferred_constraints

tests/schema/tests.py:1267–1281  ·  view source on GitHub ↗

#25492 - Altering a foreign key's structure and data in the same transaction.

(self)

Source from the content-addressed store, hash-verified

1265
1266 @skipUnlessDBFeature("can_defer_constraint_checks", "can_rollback_ddl")
1267 def test_alter_fk_checks_deferred_constraints(self):
1268 """
1269 #25492 - Altering a foreign key's structure and data in the same
1270 transaction.
1271 """
1272 with connection.schema_editor() as editor:
1273 editor.create_model(Node)
1274 old_field = Node._meta.get_field("parent")
1275 new_field = ForeignKey(Node, CASCADE)
1276 new_field.set_attributes_from_name("parent")
1277 parent = Node.objects.create()
1278 with connection.schema_editor() as editor:
1279 # Update the parent FK to create a deferred constraint check.
1280 Node.objects.update(parent=parent)
1281 editor.alter_field(Node, old_field, new_field, strict=True)
1282
1283 @isolate_apps("schema")
1284 def test_alter_null_with_default_value_deferred_constraints(self):

Callers

nothing calls this directly

Calls 8

ForeignKeyClass · 0.90
schema_editorMethod · 0.80
create_modelMethod · 0.45
get_fieldMethod · 0.45
createMethod · 0.45
updateMethod · 0.45
alter_fieldMethod · 0.45

Tested by

no test coverage detected