|
@@ -27,8 +27,8 @@ from .fields import (
|
|
|
from .models import (
|
|
|
Author, AuthorWithDefaultHeight, AuthorWithEvenLongerName, Book,
|
|
|
BookForeignObj, BookWeak, BookWithLongName, BookWithO2O, BookWithoutAuthor,
|
|
|
- BookWithSlug, IntegerPK, Note, NoteRename, Tag, TagIndexed, TagM2MTest,
|
|
|
- TagUniqueRename, Thing, UniqueTest, new_apps,
|
|
|
+ BookWithSlug, IntegerPK, Node, Note, NoteRename, Tag, TagIndexed,
|
|
|
+ TagM2MTest, TagUniqueRename, Thing, UniqueTest, new_apps,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -1819,3 +1819,14 @@ class SchemaTests(TransactionTestCase):
|
|
|
self.get_constraints_for_column(Tag, 'slug'),
|
|
|
['schema_tag_slug_2c418ba3_like', 'schema_tag_slug_key']
|
|
|
)
|
|
|
+
|
|
|
+ def test_alter_pk_with_self_referential_field(self):
|
|
|
+ """
|
|
|
+ Changing the primary key field name of a model with a self-referential
|
|
|
+ foreign key (#26384).
|
|
|
+ """
|
|
|
+ old_field = Node._meta.get_field('node_id')
|
|
|
+ new_field = AutoField(primary_key=True)
|
|
|
+ new_field.set_attributes_from_name('id')
|
|
|
+ with connection.schema_editor() as editor:
|
|
|
+ editor.alter_field(Node, old_field, new_field)
|