mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #27195 -- Stopped dropping default when adding a nullable column.
Thanks Rob Golding from Zapier for the report.
This commit is contained in:
parent
331ca5391e
commit
aca939b6e5
2 changed files with 7 additions and 2 deletions
|
@ -21,6 +21,7 @@ from django.db.transaction import atomic
|
|||
from django.test import (
|
||||
TransactionTestCase, mock, skipIfDBFeature, skipUnlessDBFeature,
|
||||
)
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
from django.utils.timezone import UTC
|
||||
|
||||
from .fields import (
|
||||
|
@ -347,8 +348,12 @@ class SchemaTests(TransactionTestCase):
|
|||
# Add the new field
|
||||
new_field = IntegerField(null=True)
|
||||
new_field.set_attributes_from_name("age")
|
||||
with connection.schema_editor() as editor:
|
||||
with CaptureQueriesContext(connection) as ctx, connection.schema_editor() as editor:
|
||||
editor.add_field(Author, new_field)
|
||||
drop_default_sql = editor.sql_alter_column_no_default % {
|
||||
'column': editor.quote_name(new_field.name),
|
||||
}
|
||||
self.assertFalse(any(drop_default_sql in query['sql'] for query in ctx.captured_queries))
|
||||
# Ensure the field is right afterwards
|
||||
columns = self.column_classes(Author)
|
||||
self.assertEqual(columns['age'][0], "IntegerField")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue