summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorsarahboyce <sarahvboyce95@gmail.com>2022-04-01 20:21:43 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-04-06 13:05:57 +0200
commit65effbdb101714ac98b3f143eaccadd8e4f08361 (patch)
tree89bbbb2d6b58c3aeae7d1149149c9382af866022 /tests/schema
parent6991880109e35c879b71b7d9d9c154baeec12b89 (diff)
downloaddjango-65effbdb101714ac98b3f143eaccadd8e4f08361.tar.gz
Fixed #33471 -- Made AlterField operation a noop when changing "choices".
This also allows customizing attributes of fields that don't affect a column definition.
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index d9e59d32dc..fcc090aaf2 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -3961,6 +3961,20 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor, self.assertNumQueries(0):
editor.alter_field(Book, new_field, old_field, strict=True)
+ def test_alter_field_choices_noop(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ old_field = Author._meta.get_field("name")
+ new_field = CharField(
+ choices=(("Jane", "Jane"), ("Joe", "Joe")),
+ max_length=255,
+ )
+ new_field.set_attributes_from_name("name")
+ with connection.schema_editor() as editor, self.assertNumQueries(0):
+ editor.alter_field(Author, old_field, new_field, strict=True)
+ with connection.schema_editor() as editor, self.assertNumQueries(0):
+ editor.alter_field(Author, new_field, old_field, strict=True)
+
def test_add_textfield_unhashable_default(self):
# Create the table
with connection.schema_editor() as editor: