1
0
mirror of https://github.com/django/django.git synced 2025-10-30 09:06:13 +00:00

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.
This commit is contained in:
Claude Paroz
2015-04-11 16:10:31 +02:00
parent ed336a1a5d
commit 02260ea3f6
7 changed files with 80 additions and 26 deletions

View File

@@ -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)