summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/schema/tests.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index fc2c56887f..6cfc30a415 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -8,14 +8,14 @@ from django.db import (
)
from django.db.models import Model
from django.db.models.fields import (
- BinaryField, BooleanField, CharField, DateTimeField, IntegerField,
- PositiveIntegerField, SlugField, TextField,
+ BigIntegerField, BinaryField, BooleanField, CharField, DateTimeField,
+ IntegerField, PositiveIntegerField, SlugField, TextField,
)
from django.db.models.fields.related import (
ForeignKey, ManyToManyField, OneToOneField,
)
from django.db.transaction import atomic
-from django.test import TransactionTestCase
+from django.test import TransactionTestCase, skipIfDBFeature
from .fields import CustomManyToManyField, InheritedManyToManyField
from .models import (
@@ -426,7 +426,8 @@ 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):
+ @skipIfDBFeature('interprets_empty_strings_as_nulls')
+ def test_alter_textual_field_keep_null_status(self):
"""
Changing a field type shouldn't affect the not null status.
"""
@@ -442,6 +443,22 @@ class SchemaTests(TransactionTestCase):
with self.assertRaises(IntegrityError):
Note.objects.create(info=None)
+ def test_alter_numeric_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(UniqueTest)
+ with self.assertRaises(IntegrityError):
+ UniqueTest.objects.create(year=None, slug='aaa')
+ old_field = UniqueTest._meta.get_field("year")
+ new_field = BigIntegerField()
+ new_field.set_attributes_from_name("year")
+ with connection.schema_editor() as editor:
+ editor.alter_field(UniqueTest, old_field, new_field, strict=True)
+ with self.assertRaises(IntegrityError):
+ UniqueTest.objects.create(year=None, slug='bbb')
+
def test_alter_null_to_not_null(self):
"""
#23609 - Tests handling of default values when altering from NULL to NOT NULL.