Fixed -- Avoided unnecessary SchemaEditor.effective_default() calls when altering a field.
@@ -675,16 +675,16 @@ class BaseDatabaseSchemaEditor:
# 3. Replace NULL constraint with NOT NULL
# 4. Drop the default again.
# Default change?
+ needs_database_default = False
+ if old_field.null and not new_field.null:
old_default = self.effective_default(old_field)
new_default = self.effective_default(new_field)
- needs_database_default = (
- old_field.null and
- not new_field.null and
+ if (
+ not self.skip_default(new_field) and
old_default != new_default and
- new_default is not None and
- not self.skip_default(new_field)
- )
- if needs_database_default:
+ new_default is not None
+ ):
+ needs_database_default = True
actions.append(self._alter_column_default_sql(model, old_field, new_field))
# Nullability change?
if old_field.null != new_field.null:
