summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 7dfad1b5d6..9e23c4608e 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -863,6 +863,27 @@ class SchemaTests(TransactionTestCase):
with self.assertRaises(IntegrityError):
Note.objects.create(info=None)
+ @skipUnlessDBFeature('interprets_empty_strings_as_nulls')
+ def test_alter_textual_field_not_null_to_null(self):
+ """
+ Nullability for textual fields is preserved on databases that
+ interpret empty strings as NULLs.
+ """
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ columns = self.column_classes(Author)
+ # Field is nullable.
+ self.assertTrue(columns['uuid'][1][6])
+ # Change to NOT NULL.
+ old_field = Author._meta.get_field('uuid')
+ new_field = SlugField(null=False, blank=True)
+ new_field.set_attributes_from_name('uuid')
+ with connection.schema_editor() as editor:
+ editor.alter_field(Author, old_field, new_field, strict=True)
+ columns = self.column_classes(Author)
+ # Nullability is preserved.
+ self.assertTrue(columns['uuid'][1][6])
+
def test_alter_numeric_field_keep_null_status(self):
"""
Changing a field type shouldn't affect the not null status.