1
0
mirror of https://github.com/django/django.git synced 2025-10-30 17:16:10 +00:00

Fixed #24817 -- Prevented loss of null info in MySQL field renaming.

This commit is contained in:
Andriy Sokolovskiy
2015-05-27 01:18:21 +03:00
committed by Tim Graham
parent 300e8baf94
commit 80ad5472ce
7 changed files with 67 additions and 11 deletions

View File

@@ -80,10 +80,21 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
)
return super(DatabaseSchemaEditor, self)._delete_composed_index(model, fields, *args)
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:
def _set_field_new_type_null_status(self, field, new_type):
"""
Keep the null property of the old field. If it has changed, it will be
handled separately.
"""
if field.null:
new_type += " NULL"
else:
new_type += " NOT NULL"
return new_type
def _alter_column_type_sql(self, table, old_field, new_field, new_type):
new_type = self._set_field_new_type_null_status(old_field, new_type)
return super(DatabaseSchemaEditor, self)._alter_column_type_sql(table, old_field, new_field, new_type)
def _rename_field_sql(self, table, old_field, new_field, new_type):
new_type = self._set_field_new_type_null_status(old_field, new_type)
return super(DatabaseSchemaEditor, self)._rename_field_sql(table, old_field, new_field, new_type)