summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/mysql/schema.py')
-rw-r--r--django/db/backends/mysql/schema.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py
index 37c130e908..15286a67a1 100644
--- a/django/db/backends/mysql/schema.py
+++ b/django/db/backends/mysql/schema.py
@@ -49,10 +49,21 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
'column': self.quote_name(field.column),
}, [effective_default])
- 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)