summaryrefslogtreecommitdiff
path: root/tests
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 10:25:15 +0200
commit02260ea3f61b2fe0a0178528526101ff578c7400 (patch)
tree38a8364b8e353a72158532b15ed6c6ac2c9931ed /tests
parented336a1a5d3991acef2208b7aaf9fbe99af48a14 (diff)
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_operations.py13
-rw-r--r--tests/schema/tests.py16
2 files changed, 27 insertions, 2 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index b5faa8f0f6..b8354f32d9 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1101,9 +1101,18 @@ class OperationTests(OperationTestBase):
def assertIdTypeEqualsFkType():
with connection.cursor() as cursor:
- id_type = [c.type_code for c in connection.introspection.get_table_description(cursor, "test_alflpkfk_pony") if c.name == "id"][0]
- fk_type = [c.type_code for c in connection.introspection.get_table_description(cursor, "test_alflpkfk_rider") if c.name == "pony_id"][0]
+ id_type, id_null = [
+ (c.type_code, c.null_ok)
+ for c in connection.introspection.get_table_description(cursor, "test_alflpkfk_pony")
+ if c.name == "id"
+ ][0]
+ fk_type, fk_null = [
+ (c.type_code, c.null_ok)
+ for c in connection.introspection.get_table_description(cursor, "test_alflpkfk_rider")
+ if c.name == "pony_id"
+ ][0]
self.assertEqual(id_type, fk_type)
+ self.assertEqual(id_null, fk_null)
assertIdTypeEqualsFkType()
# Test the database alteration
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index f6b80b9c83..fc2c56887f 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.