summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndriy Sokolovskiy <sokandpal@yandex.ru>2014-12-15 16:14:39 +0200
committerTim Graham <timograham@gmail.com>2014-12-15 13:42:08 -0500
commit1690b92b0d53e625ef6623a317149013725015af (patch)
treecaeaf42469d8ac51a487712547134a2fb6bf0f3f /tests
parenteb632bfba51263f9a91e1699be25dac7b7bab53e (diff)
[1.7.x] Fixed #23987 -- Made SQLite SchemaEditor always use effective_default().
Backport of 089047331d972c0ee58d13476fc54f2118bf1359 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 4c773599f9..eb46b38e48 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -1180,3 +1180,27 @@ class SchemaTests(TransactionTestCase):
}
)
editor.alter_field(model, get_field(Author, field_class=ForeignKey), field)
+
+ def test_add_field_use_effective_default(self):
+ """
+ #23987 - effective_default() should be used as the field default when
+ adding a new field.
+ """
+ # Create the table
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ # Ensure there's no surname field
+ columns = self.column_classes(Author)
+ self.assertNotIn("surname", columns)
+ # Create a row
+ Author.objects.create(name='Anonymous1')
+ # Add new CharField to ensure default will be used from effective_default
+ new_field = CharField(max_length=15, blank=True)
+ new_field.set_attributes_from_name("surname")
+ with connection.schema_editor() as editor:
+ editor.add_field(Author, new_field)
+ # Ensure field was added with the right default
+ with connection.cursor() as cursor:
+ cursor.execute("SELECT surname FROM schema_author;")
+ item = cursor.fetchall()[0]
+ self.assertEqual(item[0], '')