mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #28541 -- Fixed migrations crash when changing primary key on SQLite.
This commit is contained in:
committed by
Mariusz Felisiak
parent
3d7235c67b
commit
593067a8ee
@@ -229,6 +229,14 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
body_copy["__module__"] = model.__module__
|
||||
new_model = type("New%s" % model._meta.object_name, model.__bases__, body_copy)
|
||||
|
||||
# Remove the automatically recreated default primary key, if it has
|
||||
# been deleted.
|
||||
if delete_field and delete_field.attname == new_model._meta.pk.attname:
|
||||
auto_pk = new_model._meta.pk
|
||||
delattr(new_model, auto_pk.attname)
|
||||
new_model._meta.local_fields.remove(auto_pk)
|
||||
new_model.pk = None
|
||||
|
||||
# Create a new table with the updated schema.
|
||||
self.create_model(new_model)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user