1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #33080 -- Preserved nullability of textual fields on Oracle.

Thanks Matt Hoskins for the report.
This commit is contained in:
Mariusz Felisiak
2021-09-01 13:26:46 +02:00
parent f65eb46646
commit 338fc0e7f1
2 changed files with 25 additions and 2 deletions

View File

@@ -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.