MCPcopy
hub / github.com/django/django / test_alter_pk_with_self_referential_field

Method test_alter_pk_with_self_referential_field

tests/schema/tests.py:5462–5474  ·  view source on GitHub ↗

Changing the primary key field name of a model with a self-referential foreign key (#26384).

(self)

Source from the content-addressed store, hash-verified

5460 self.assertEqual(self.get_constraints_for_column(Author, "weight"), [])
5461
5462 def test_alter_pk_with_self_referential_field(self):
5463 """
5464 Changing the primary key field name of a model with a self-referential
5465 foreign key (#26384).
5466 """
5467 with connection.schema_editor() as editor:
5468 editor.create_model(Node)
5469 old_field = Node._meta.get_field("node_id")
5470 new_field = AutoField(primary_key=True)
5471 new_field.set_attributes_from_name("id")
5472 with connection.schema_editor() as editor:
5473 editor.alter_field(Node, old_field, new_field, strict=True)
5474 self.assertForeignKeyExists(Node, "parent_id", Node._meta.db_table)
5475
5476 @mock.patch("django.db.backends.base.schema.datetime")
5477 @mock.patch("django.db.backends.base.schema.timezone")

Callers

nothing calls this directly

Calls 7

AutoFieldClass · 0.90
schema_editorMethod · 0.80
create_modelMethod · 0.45
get_fieldMethod · 0.45
alter_fieldMethod · 0.45

Tested by

no test coverage detected