summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-01-19 17:10:24 +0000
committerAndrew Godwin <andrew@aeracode.org>2014-01-19 17:10:24 +0000
commite802c97581594e3a37e6497443b105ecb9920a55 (patch)
treeb631d58d9d2d99993b34b5ac31277e99b3cadd2a /tests
parentc9de1b4a55713ad1557f8c40621226253038f665 (diff)
Fixed #21783: Use defaults for adding NOT NULL on sqlite
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index e0000e2b9d..6e92d5b784 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -145,7 +145,7 @@ class SchemaTests(TransactionTestCase):
# Ensure there's no age field
columns = self.column_classes(Author)
self.assertNotIn("age", columns)
- # Alter the name field to a TextField
+ # Add the new field
new_field = IntegerField(null=True)
new_field.set_attributes_from_name("age")
with connection.schema_editor() as editor:
@@ -158,6 +158,32 @@ class SchemaTests(TransactionTestCase):
self.assertEqual(columns['age'][0], "IntegerField")
self.assertEqual(columns['age'][1][6], True)
+ def test_add_field_temp_default(self):
+ """
+ Tests adding fields to models with a temporary default
+ """
+ # Create the table
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ # Ensure there's no age field
+ columns = self.column_classes(Author)
+ self.assertNotIn("age", columns)
+ # Add some rows of data
+ Author.objects.create(name="Andrew", height=30)
+ Author.objects.create(name="Andrea")
+ # Add a not-null field
+ new_field = CharField(max_length=30, default="Godwin")
+ new_field.set_attributes_from_name("surname")
+ with connection.schema_editor() as editor:
+ editor.add_field(
+ Author,
+ new_field,
+ )
+ # Ensure the field is right afterwards
+ columns = self.column_classes(Author)
+ self.assertEqual(columns['surname'][0], "CharField")
+ self.assertEqual(columns['surname'][1][6], False)
+
def test_alter(self):
"""
Tests simple altering of fields