Loading django/db/backends/mysql/schema.py +14 −3 Original line number Diff line number Diff line Loading @@ -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) django/db/backends/schema.py +9 −6 Original line number Diff line number Diff line Loading @@ -527,12 +527,7 @@ class BaseDatabaseSchemaEditor(object): self.execute(self._delete_constraint_sql(self.sql_delete_check, model, constraint_name)) # Have they renamed the column? if old_field.column != new_field.column: self.execute(self.sql_rename_column % { "table": self.quote_name(model._meta.db_table), "old_column": self.quote_name(old_field.column), "new_column": self.quote_name(new_field.column), "type": new_type, }) self.execute(self._rename_field_sql(model._meta.db_table, old_field, new_field, new_type)) # Next, start accumulating actions to do actions = [] null_actions = [] Loading Loading @@ -841,6 +836,14 @@ class BaseDatabaseSchemaEditor(object): output.append(self._create_index_sql(model, fields, suffix="_idx")) return output def _rename_field_sql(self, table, old_field, new_field, new_type): return self.sql_rename_column % { "table": self.quote_name(table), "old_column": self.quote_name(old_field.column), "new_column": self.quote_name(new_field.column), "type": new_type, } def _create_fk_sql(self, model, field, suffix): from_table = model._meta.db_table from_column = field.column Loading docs/releases/1.7.9.txt 0 → 100644 +10 −0 Original line number Diff line number Diff line ========================== Django 1.7.9 release notes ========================== *Under development* Django 1.7.9 fixes several bugs in 1.7.8. * Prevented the loss of ``null``/``not null`` column properties during field renaming of MySQL databases (:ticket:`24817`). docs/releases/index.txt +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ versions of the documentation contain the release notes for any later releases. .. toctree:: :maxdepth: 1 1.7.9 1.7.8 1.7.7 1.7.6 Loading tests/schema/models.py +8 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,14 @@ class BookWithSlug(models.Model): db_table = "schema_book" class NoteRename(models.Model): detail_info = models.TextField() class Meta: apps = new_apps db_table = "schema_note" class Tag(models.Model): title = models.CharField(max_length=255) slug = models.SlugField(unique=True) Loading Loading
django/db/backends/mysql/schema.py +14 −3 Original line number Diff line number Diff line Loading @@ -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)
django/db/backends/schema.py +9 −6 Original line number Diff line number Diff line Loading @@ -527,12 +527,7 @@ class BaseDatabaseSchemaEditor(object): self.execute(self._delete_constraint_sql(self.sql_delete_check, model, constraint_name)) # Have they renamed the column? if old_field.column != new_field.column: self.execute(self.sql_rename_column % { "table": self.quote_name(model._meta.db_table), "old_column": self.quote_name(old_field.column), "new_column": self.quote_name(new_field.column), "type": new_type, }) self.execute(self._rename_field_sql(model._meta.db_table, old_field, new_field, new_type)) # Next, start accumulating actions to do actions = [] null_actions = [] Loading Loading @@ -841,6 +836,14 @@ class BaseDatabaseSchemaEditor(object): output.append(self._create_index_sql(model, fields, suffix="_idx")) return output def _rename_field_sql(self, table, old_field, new_field, new_type): return self.sql_rename_column % { "table": self.quote_name(table), "old_column": self.quote_name(old_field.column), "new_column": self.quote_name(new_field.column), "type": new_type, } def _create_fk_sql(self, model, field, suffix): from_table = model._meta.db_table from_column = field.column Loading
docs/releases/1.7.9.txt 0 → 100644 +10 −0 Original line number Diff line number Diff line ========================== Django 1.7.9 release notes ========================== *Under development* Django 1.7.9 fixes several bugs in 1.7.8. * Prevented the loss of ``null``/``not null`` column properties during field renaming of MySQL databases (:ticket:`24817`).
docs/releases/index.txt +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ versions of the documentation contain the release notes for any later releases. .. toctree:: :maxdepth: 1 1.7.9 1.7.8 1.7.7 1.7.6 Loading
tests/schema/models.py +8 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,14 @@ class BookWithSlug(models.Model): db_table = "schema_book" class NoteRename(models.Model): detail_info = models.TextField() class Meta: apps = new_apps db_table = "schema_note" class Tag(models.Model): title = models.CharField(max_length=255) slug = models.SlugField(unique=True) Loading