summaryrefslogtreecommitdiff
path: root/tests/schema/tests.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-10-01 07:53:32 +0200
committerGitHub <noreply@github.com>2022-10-01 07:53:32 +0200
commitbc3b8f152452ba0e41f28baa93c0bf8f39cddb09 (patch)
tree2f0bd277e505d6bb4b04e7112cacae9649b001e9 /tests/schema/tests.py
parent5e0aa362d91d000984995ce374c2d7547d8d107f (diff)
Refs #34058 -- Fixed changing/deleting sequences when altering pre-Django 4.1 auto fields on PostgreSQL.
Thanks Anders Kaseorg for the report. Follow up to 19e6efa50b603af325e7f62058364f278596758f. Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6.
Diffstat (limited to 'tests/schema/tests.py')
-rw-r--r--tests/schema/tests.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 32dde9aaed..a2b72cd42a 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -1896,14 +1896,30 @@ class SchemaTests(TransactionTestCase):
new_field.set_attributes_from_name("id")
with connection.schema_editor() as editor:
editor.alter_field(SerialAutoField, old_field, new_field, strict=True)
+ sequence_name = f"{table}_{column}_seq"
with connection.cursor() as cursor:
cursor.execute(
"SELECT data_type FROM pg_sequences WHERE sequencename = %s",
- [f"{table}_{column}_seq"],
+ [sequence_name],
)
row = cursor.fetchone()
sequence_data_type = row[0] if row and row[0] else None
self.assertEqual(sequence_data_type, "bigint")
+ # Rename the column.
+ old_field = new_field
+ new_field = AutoField(primary_key=True)
+ new_field.model = SerialAutoField
+ new_field.set_attributes_from_name("renamed_id")
+ with connection.schema_editor() as editor:
+ editor.alter_field(SerialAutoField, old_field, new_field, strict=True)
+ with connection.cursor() as cursor:
+ cursor.execute(
+ "SELECT data_type FROM pg_sequences WHERE sequencename = %s",
+ [sequence_name],
+ )
+ row = cursor.fetchone()
+ sequence_data_type = row[0] if row and row[0] else None
+ self.assertEqual(sequence_data_type, "integer")
finally:
with connection.cursor() as cursor:
cursor.execute(f'DROP TABLE "{table}"')