summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoƮt Vinot <benoit.vinot@roseautechnologies.com>2022-08-17 13:19:16 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-17 17:43:48 +0200
commit85942cf6692f44d11d6d574b2429d201cc1e0aa7 (patch)
tree60a793c273fdeb8e8695f6691cf7f82942f1aff7 /tests
parentbee09df39fe0734eb2388a2b3439436796592820 (diff)
[4.1.x] Fixed #33932 -- Fixed altering AutoFields to OneToOneField on PostgreSQL.
Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6. Backport of e3cb8bcb7d2a2d392e726ee1f7e32a8d9038e14c from main
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 94e9c8e0d7..bb8c923c1e 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -1500,6 +1500,32 @@ class SchemaTests(TransactionTestCase):
# OneToOneField.
self.assertEqual(counts, {"fks": expected_fks, "uniques": 1, "indexes": 0})
+ def test_autofield_to_o2o(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Note)
+
+ # Rename the field.
+ old_field = Author._meta.get_field("id")
+ new_field = AutoField(primary_key=True)
+ new_field.set_attributes_from_name("note_ptr")
+ new_field.model = Author
+
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, old_field, new_field, strict=True)
+ # Alter AutoField to OneToOneField.
+ new_field_o2o = OneToOneField(Note, CASCADE)
+ new_field_o2o.set_attributes_from_name("note_ptr")
+ new_field_o2o.model = Author
+
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, new_field, new_field_o2o, strict=True)
+ columns = self.column_classes(Author)
+ field_type, _ = columns["note_ptr_id"]
+ self.assertEqual(
+ field_type, connection.features.introspected_field_types["IntegerField"]
+ )
+
def test_alter_field_fk_keeps_index(self):
with connection.schema_editor() as editor:
editor.create_model(Author)