summaryrefslogtreecommitdiff
path: root/tests/schema/tests.py
diff options
context:
space:
mode:
authorBen Cail <bcail@crossway.org>2024-09-17 15:10:39 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-10-31 06:37:14 +0100
commit0eaaadd47fa00baabe12be3ed736aa016b6d327e (patch)
tree4d05f91ac6224e7a6a658106aecfe6bee8729d65 /tests/schema/tests.py
parentb50d1a020d3a988ab9f45724138943dc807c5ecc (diff)
Fixed #35180 -- Recreated PostgreSQL _like indexes when changing between TextField and CharField field types.
Diffstat (limited to 'tests/schema/tests.py')
-rw-r--r--tests/schema/tests.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 33a4bc527b..935267c2d6 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -5223,6 +5223,51 @@ class SchemaTests(TransactionTestCase):
["schema_tag_slug_2c418ba3_like", "schema_tag_slug_key"],
)
+ @isolate_apps("schema")
+ @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific")
+ def test_indexed_charfield_to_textfield(self):
+ class SimpleModel(Model):
+ field1 = CharField(max_length=10, db_index=True)
+
+ class Meta:
+ app_label = "schema"
+
+ with connection.schema_editor() as editor:
+ editor.create_model(SimpleModel)
+ self.assertEqual(
+ self.get_constraints_for_column(SimpleModel, "field1"),
+ [
+ "schema_simplemodel_field1_f07a3d6a",
+ "schema_simplemodel_field1_f07a3d6a_like",
+ ],
+ )
+ # Change to TextField.
+ old_field1 = SimpleModel._meta.get_field("field1")
+ new_field1 = TextField(db_index=True)
+ new_field1.set_attributes_from_name("field1")
+ with connection.schema_editor() as editor:
+ editor.alter_field(SimpleModel, old_field1, new_field1, strict=True)
+ self.assertEqual(
+ self.get_constraints_for_column(SimpleModel, "field1"),
+ [
+ "schema_simplemodel_field1_f07a3d6a",
+ "schema_simplemodel_field1_f07a3d6a_like",
+ ],
+ )
+ # Change back to CharField.
+ old_field1 = SimpleModel._meta.get_field("field1")
+ new_field1 = CharField(max_length=10, db_index=True)
+ new_field1.set_attributes_from_name("field1")
+ with connection.schema_editor() as editor:
+ editor.alter_field(SimpleModel, old_field1, new_field1, strict=True)
+ self.assertEqual(
+ self.get_constraints_for_column(SimpleModel, "field1"),
+ [
+ "schema_simplemodel_field1_f07a3d6a",
+ "schema_simplemodel_field1_f07a3d6a_like",
+ ],
+ )
+
def test_alter_field_add_index_to_integerfield(self):
# Create the table and verify no initial indexes.
with connection.schema_editor() as editor: