diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-07-21 10:03:51 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-07-21 10:04:53 +0100 |
| commit | 2fb1939a9efae24560d41fbb7f6a280a1d2e8d06 (patch) | |
| tree | 8ffb54126ef75e4c4906444c434f334cf4b57f58 | |
| parent | 63ae8de8fcc2fff581608ff0587f6497b38ba909 (diff) | |
[1.7.x] Fixed #23043: alter_field drops defaults too
| -rw-r--r-- | django/db/backends/schema.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index 8fdc3083c9..d4573a4be8 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -766,6 +766,16 @@ class BaseDatabaseSchemaEditor(object): "check": new_db_params['check'], } ) + # Drop the default if we need to + # (Django usually does not use in-database defaults) + if not self.skip_default(new_field) and new_field.default is not None: + sql = self.sql_alter_column % { + "table": self.quote_name(model._meta.db_table), + "changes": self.sql_alter_column_no_default % { + "column": self.quote_name(new_field.column), + } + } + self.execute(sql) # Reset connection if required if self.connection.features.connection_persists_old_columns: self.connection.close() |
