Fixed #31392 -- Avoided unnecessary SchemaEditor.effective_default() calls when altering a field.
This commit is contained in:
parent
be648d1c45
commit
8fe2447a01
|
@ -675,17 +675,17 @@ class BaseDatabaseSchemaEditor:
|
||||||
# 3. Replace NULL constraint with NOT NULL
|
# 3. Replace NULL constraint with NOT NULL
|
||||||
# 4. Drop the default again.
|
# 4. Drop the default again.
|
||||||
# Default change?
|
# Default change?
|
||||||
old_default = self.effective_default(old_field)
|
needs_database_default = False
|
||||||
new_default = self.effective_default(new_field)
|
if old_field.null and not new_field.null:
|
||||||
needs_database_default = (
|
old_default = self.effective_default(old_field)
|
||||||
old_field.null and
|
new_default = self.effective_default(new_field)
|
||||||
not new_field.null and
|
if (
|
||||||
old_default != new_default and
|
not self.skip_default(new_field) and
|
||||||
new_default is not None and
|
old_default != new_default and
|
||||||
not self.skip_default(new_field)
|
new_default is not None
|
||||||
)
|
):
|
||||||
if needs_database_default:
|
needs_database_default = True
|
||||||
actions.append(self._alter_column_default_sql(model, old_field, new_field))
|
actions.append(self._alter_column_default_sql(model, old_field, new_field))
|
||||||
# Nullability change?
|
# Nullability change?
|
||||||
if old_field.null != new_field.null:
|
if old_field.null != new_field.null:
|
||||||
fragment = self._alter_column_null_sql(model, old_field, new_field)
|
fragment = self._alter_column_null_sql(model, old_field, new_field)
|
||||||
|
|
Loading…
Reference in New Issue