Django model instances primary keys do not reset to 1 after all instances are deleted

前端 未结 7 758
说谎
说谎 2020-11-29 05:27

I have been working on an offline version of my Django web app and have frequently deleted model instances for a certain ModelX.

I have done this from the admin page

7条回答
  •  旧时难觅i
    2020-11-29 05:58

    As others have stated, this is entirely the responsibility of the database.

    But you should realize that this is the desirable behaviour. An ID uniquely identifies an entity in your database. As such, it should only ever refer to one row. If that row is subsequently deleted, there's no reason why you should want a new row to re-use that ID: if you did that, you'd create a confusion between the now-deleted entity that used to have that ID, and the newly-created one that's reused it. There's no point in doing this and you should not want to do so.

提交回复
热议问题