summaryrefslogtreecommitdiff
path: root/tests/schema/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/schema/tests.py')
-rw-r--r--tests/schema/tests.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 20a00e29f7..72f90c934b 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2257,6 +2257,23 @@ class SchemaTests(TransactionTestCase):
columns = self.column_classes(AuthorDbDefault)
self.assertEqual(columns["renamed_year"][1].default, "1985")
+ @isolate_apps("schema")
+ def test_add_field_both_defaults_preserves_db_default(self):
+ class Author(Model):
+ class Meta:
+ app_label = "schema"
+
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+
+ field = IntegerField(default=1985, db_default=1988)
+ field.set_attributes_from_name("birth_year")
+ field.model = Author
+ with connection.schema_editor() as editor:
+ editor.add_field(Author, field)
+ columns = self.column_classes(Author)
+ self.assertEqual(columns["birth_year"][1].default, "1988")
+
@skipUnlessDBFeature(
"supports_column_check_constraints", "can_introspect_check_constraints"
)