summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index fee5ca9d2b..9b2b512c1b 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -4951,6 +4951,38 @@ class SchemaTests(TransactionTestCase):
self.assertIsNone(self.get_column_collation(Author._meta.db_table, "name"))
@skipUnlessDBFeature("supports_collation_on_charfield")
+ def test_alter_field_type_preserve_db_collation(self):
+ collation = connection.features.test_collations.get("non_default")
+ if not collation:
+ self.skipTest("Language collations are not supported.")
+
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+
+ old_field = Author._meta.get_field("name")
+ new_field = CharField(max_length=255, db_collation=collation)
+ new_field.set_attributes_from_name("name")
+ new_field.model = Author
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, old_field, new_field, strict=True)
+ self.assertEqual(
+ self.get_column_collation(Author._meta.db_table, "name"),
+ collation,
+ )
+ # Changing a field type should preserve the collation.
+ old_field = new_field
+ new_field = CharField(max_length=511, db_collation=collation)
+ new_field.set_attributes_from_name("name")
+ new_field.model = Author
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, new_field, old_field, strict=True)
+ # Collation is preserved.
+ self.assertEqual(
+ self.get_column_collation(Author._meta.db_table, "name"),
+ collation,
+ )
+
+ @skipUnlessDBFeature("supports_collation_on_charfield")
def test_alter_primary_key_db_collation(self):
collation = connection.features.test_collations.get("non_default")
if not collation: