summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-12 17:30:23 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-12 17:31:15 +0200
commit3848475eeb5ee8f7729440f50c04fd85cf8bea66 (patch)
tree0b8ba219503a95383e58ac36bccc24b5719d1c63 /tests
parent04ec8bf92a0c3f3d89adbc38a187f972b8424941 (diff)
[4.1.x] Fixed #33919 -- Fixed adding AutoFields on PostgreSQL.
Thanks Jack Calvin Brown for the report. Regression in 2eea361eff58dd98c409c5227064b901f41bd0d6. Backport of 5c803bc0702511c8bc05e9db600367a465514f82 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 7bd62a2f66..94e9c8e0d7 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -792,6 +792,31 @@ class SchemaTests(TransactionTestCase):
# Introspection treats BLOBs as TextFields
self.assertEqual(columns["bits"][0], "TextField")
+ @isolate_apps("schema")
+ def test_add_auto_field(self):
+ class AddAutoFieldModel(Model):
+ name = CharField(max_length=255, primary_key=True)
+
+ class Meta:
+ app_label = "schema"
+
+ with connection.schema_editor() as editor:
+ editor.create_model(AddAutoFieldModel)
+ self.isolated_local_models = [AddAutoFieldModel]
+ old_field = AddAutoFieldModel._meta.get_field("name")
+ new_field = CharField(max_length=255)
+ new_field.set_attributes_from_name("name")
+ new_field.model = AddAutoFieldModel
+ with connection.schema_editor() as editor:
+ editor.alter_field(AddAutoFieldModel, old_field, new_field)
+ new_auto_field = AutoField(primary_key=True)
+ new_auto_field.set_attributes_from_name("id")
+ new_auto_field.model = AddAutoFieldModel()
+ with connection.schema_editor() as editor:
+ editor.add_field(AddAutoFieldModel, new_auto_field)
+ # Crashes on PostgreSQL when the GENERATED BY suffix is missing.
+ AddAutoFieldModel.objects.create(name="test")
+
def test_remove_field(self):
with connection.schema_editor() as editor:
editor.create_model(Author)