diff options
| author | Shipeng Feng <fsp261@gmail.com> | 2020-03-24 20:09:43 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-24 13:09:43 +0100 |
| commit | 8fe2447a01232d9598bf4692d1face12fa074288 (patch) | |
| tree | b2923f11f89880821f61795a6016a92357a099ad | |
| parent | be648d1c457a13af27bc310568c95ab6f08610dd (diff) | |
Fixed #31392 -- Avoided unnecessary SchemaEditor.effective_default() calls when altering a field.
| -rw-r--r-- | django/db/backends/base/schema.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py index bfccf5e8fb..8cd5e11bbf 100644 --- a/django/db/backends/base/schema.py +++ b/django/db/backends/base/schema.py @@ -675,17 +675,17 @@ class BaseDatabaseSchemaEditor: # 3. Replace NULL constraint with NOT NULL # 4. Drop the default again. # Default change? - 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 - old_default != new_default and - new_default is not None and - not self.skip_default(new_field) - ) - if needs_database_default: - actions.append(self._alter_column_default_sql(model, old_field, new_field)) + 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) + if ( + not self.skip_default(new_field) and + old_default != new_default and + 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: fragment = self._alter_column_null_sql(model, old_field, new_field) |
