summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-04-11 16:10:31 +0200
committerClaude Paroz <claude@2xlibre.net>2015-04-17 11:01:36 +0200
commitbbfcd9618b06556a0ae2c38456ef38bf3bea9e9d (patch)
treebbfadf2f0cb3fb8ef91830b98fb1a27452d3b9e4 /tests/schema
parentd0b18542f740b358fb776e2b158ac69ff154896e (diff)
[1.8.x] Fixed #24595 -- Prevented loss of null info in MySQL field alteration
Thanks Simon Percivall for the report, and Simon Charette and Tim Graham for the reviews. Backport of 02260ea3f6 from master.
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 2f4a84db09..7027d716b0 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -426,6 +426,22 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor:
editor.alter_field(Note, old_field, new_field, strict=True)
+ def test_alter_field_keep_null_status(self):
+ """
+ Changing a field type shouldn't affect the not null status.
+ """
+ with connection.schema_editor() as editor:
+ editor.create_model(Note)
+ with self.assertRaises(IntegrityError):
+ Note.objects.create(info=None)
+ old_field = Note._meta.get_field("info")
+ new_field = CharField(max_length=50)
+ new_field.set_attributes_from_name("info")
+ with connection.schema_editor() as editor:
+ editor.alter_field(Note, old_field, new_field, strict=True)
+ with self.assertRaises(IntegrityError):
+ Note.objects.create(info=None)
+
def test_alter_null_to_not_null(self):
"""
#23609 - Tests handling of default values when altering from NULL to NOT NULL.