diff options
author | Claude Paroz <claude@2xlibre.net> | 2015-04-11 16:10:31 +0200 |
---|---|---|
committer | Claude Paroz <claude@2xlibre.net> | 2015-04-17 10:25:15 +0200 |
commit | 02260ea3f61b2fe0a0178528526101ff578c7400 (patch) | |
tree | 38a8364b8e353a72158532b15ed6c6ac2c9931ed /django/db/backends/mysql/schema.py | |
parent | ed336a1a5d3991acef2208b7aaf9fbe99af48a14 (diff) | |
download | django-02260ea3f61b2fe0a0178528526101ff578c7400.tar.gz |
Fixed #24595 -- Prevented loss of null info in MySQL field alteration
Thanks Simon Percivall for the report, and Simon Charette and Tim
Graham for the reviews.
Diffstat (limited to 'django/db/backends/mysql/schema.py')
-rw-r--r-- | django/db/backends/mysql/schema.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py index 7f3a2d357b..f2f3f0a4ed 100644 --- a/django/db/backends/mysql/schema.py +++ b/django/db/backends/mysql/schema.py @@ -61,3 +61,11 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): # index creation for FKs (index automatically created by MySQL) field.db_index = False return super(DatabaseSchemaEditor, self)._model_indexes_sql(model) + + def _alter_column_type_sql(self, table, old_field, new_field, new_type): + # Keep null property of old field, if it has changed, it will be handled separately + if old_field.null: + new_type += " NULL" + else: + new_type += " NOT NULL" + return super(DatabaseSchemaEditor, self)._alter_column_type_sql(table, old_field, new_field, new_type) |