Changing the primary key field name of a model with a self-referential foreign key (#26384).
(self)
| 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") |
nothing calls this directly
no test coverage detected