Fixed #31392 -- Avoided unnecessary SchemaEditor.effective_default() calls when altering a field.

This commit is contained in:
Shipeng Feng 2020-03-24 20:09:43 +08:00 committed by GitHub
parent be648d1c45
commit 8fe2447a01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 11 deletions

View File

@ -675,16 +675,16 @@ 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?
needs_database_default = False
if old_field.null and not new_field.null:
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)
needs_database_default = ( if (
old_field.null and not self.skip_default(new_field) and
not new_field.null and
old_default != new_default and old_default != new_default and
new_default is not None and new_default is not None
not self.skip_default(new_field) ):
) needs_database_default = True
if needs_database_default:
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: