Fixed #23581 -- Prevented extraneous DROP DEFAULT statements.
Thanks john_scott for the report and Markus Holtermann for review.
This commit is contained in:
parent
002a8ffe47
commit
ab4f709da4
|
@ -550,15 +550,12 @@ class BaseDatabaseSchemaEditor(object):
|
||||||
# Default change?
|
# Default change?
|
||||||
old_default = self.effective_default(old_field)
|
old_default = self.effective_default(old_field)
|
||||||
new_default = self.effective_default(new_field)
|
new_default = self.effective_default(new_field)
|
||||||
if old_default != new_default and not self.skip_default(new_field):
|
needs_database_default = (
|
||||||
if new_default is None:
|
old_default != new_default and
|
||||||
actions.append((
|
new_default is not None and
|
||||||
self.sql_alter_column_no_default % {
|
not self.skip_default(new_field)
|
||||||
"column": self.quote_name(new_field.column),
|
)
|
||||||
},
|
if needs_database_default:
|
||||||
[],
|
|
||||||
))
|
|
||||||
else:
|
|
||||||
if self.connection.features.requires_literal_defaults:
|
if self.connection.features.requires_literal_defaults:
|
||||||
# Some databases can't take defaults as a parameter (oracle)
|
# Some databases can't take defaults as a parameter (oracle)
|
||||||
# If this is the case, the individual schema backend should
|
# If this is the case, the individual schema backend should
|
||||||
|
@ -712,7 +709,7 @@ class BaseDatabaseSchemaEditor(object):
|
||||||
)
|
)
|
||||||
# Drop the default if we need to
|
# Drop the default if we need to
|
||||||
# (Django usually does not use in-database defaults)
|
# (Django usually does not use in-database defaults)
|
||||||
if not self.skip_default(new_field) and new_field.default is not None:
|
if needs_database_default:
|
||||||
sql = self.sql_alter_column % {
|
sql = self.sql_alter_column % {
|
||||||
"table": self.quote_name(model._meta.db_table),
|
"table": self.quote_name(model._meta.db_table),
|
||||||
"changes": self.sql_alter_column_no_default % {
|
"changes": self.sql_alter_column_no_default % {
|
||||||
|
|
|
@ -181,3 +181,5 @@ Bugfixes
|
||||||
|
|
||||||
* Supported strings escaped by third-party libraries with the ``__html__``
|
* Supported strings escaped by third-party libraries with the ``__html__``
|
||||||
convention in the template engine (:ticket:`23831`).
|
convention in the template engine (:ticket:`23831`).
|
||||||
|
|
||||||
|
* Prevented extraneous ``DROP DEFAULT`` SQL in migrations (:ticket:`23581`).
|
||||||
|
|
|
@ -547,6 +547,10 @@ class SchemaTests(TransactionTestCase):
|
||||||
strict=True,
|
strict=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# This will fail if DROP DEFAULT is inadvertently executed on this
|
||||||
|
# field which drops the id sequence, at least on PostgreSQL.
|
||||||
|
Author.objects.create(name='Foo')
|
||||||
|
|
||||||
def test_rename(self):
|
def test_rename(self):
|
||||||
"""
|
"""
|
||||||
Tests simple altering of fields
|
Tests simple altering of fields
|
||||||
|
|
Loading…
Reference in New Issue