Update primary key Django MySQL

后端 未结 3 1755
南方客
南方客 2021-01-18 10:34

sorry for my poor english, my problem is:

I try to update the PK in Django with the method .save() but when i save the object Django duplicate the object withe the s

3条回答
  •  伪装坚强ぢ
    2021-01-18 11:17

    I don't think Django allows you to change the object's primary key. You may have to delete the original object.

    e2.delete()
    

    According to the Django docs

    The primary key field is read-only. If you change the value of the primary key on an existing object and then save it, a new object will be created alongside the old one.

    Django Docs

提交回复
热议问题