Loading django/db/backends/sqlite3/schema.py +2 −2 Original line number Diff line number Diff line Loading @@ -75,8 +75,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): ) # Add in any altered fields for (old_field, new_field) in alter_fields: del body[old_field.name] del mapping[old_field.column] body.pop(old_field.name, None) mapping.pop(old_field.column, None) body[new_field.name] = new_field if old_field.null and not new_field.null: case_sql = "coalesce(%(col)s, %(default)s)" % { Loading docs/releases/1.7.2.txt +3 −0 Original line number Diff line number Diff line Loading @@ -11,3 +11,6 @@ Bugfixes * Fixed migration's renaming of auto-created many-to-many tables when changing :attr:`Meta.db_table <django.db.models.Options.db_table>` (:ticket:`23630`). * Fixed a migration crash when adding an explicit ``id`` field to a model on SQLite (:ticket:`23702`). tests/schema/tests.py +19 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,25 @@ class SchemaTests(TransactionTestCase): else: self.fail("No FK constraint for author_id found") def test_alter_implicit_id_to_explict(self): """ Should be able to convert an implicit "id" field to an explicit "id" primary key field. """ with connection.schema_editor() as editor: editor.create_model(Author) new_field = IntegerField(primary_key=True) new_field.set_attributes_from_name("id") new_field.model = Author with connection.schema_editor() as editor: editor.alter_field( Author, Author._meta.get_field_by_name("id")[0], new_field, strict=True, ) def test_rename(self): """ Tests simple altering of fields Loading Loading
django/db/backends/sqlite3/schema.py +2 −2 Original line number Diff line number Diff line Loading @@ -75,8 +75,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): ) # Add in any altered fields for (old_field, new_field) in alter_fields: del body[old_field.name] del mapping[old_field.column] body.pop(old_field.name, None) mapping.pop(old_field.column, None) body[new_field.name] = new_field if old_field.null and not new_field.null: case_sql = "coalesce(%(col)s, %(default)s)" % { Loading
docs/releases/1.7.2.txt +3 −0 Original line number Diff line number Diff line Loading @@ -11,3 +11,6 @@ Bugfixes * Fixed migration's renaming of auto-created many-to-many tables when changing :attr:`Meta.db_table <django.db.models.Options.db_table>` (:ticket:`23630`). * Fixed a migration crash when adding an explicit ``id`` field to a model on SQLite (:ticket:`23702`).
tests/schema/tests.py +19 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,25 @@ class SchemaTests(TransactionTestCase): else: self.fail("No FK constraint for author_id found") def test_alter_implicit_id_to_explict(self): """ Should be able to convert an implicit "id" field to an explicit "id" primary key field. """ with connection.schema_editor() as editor: editor.create_model(Author) new_field = IntegerField(primary_key=True) new_field.set_attributes_from_name("id") new_field.model = Author with connection.schema_editor() as editor: editor.alter_field( Author, Author._meta.get_field_by_name("id")[0], new_field, strict=True, ) def test_rename(self): """ Tests simple altering of fields Loading