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

前端 未结 7 737
说谎
说谎 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条回答
  •  死守一世寂寞
    2020-11-29 05:41

    There is no issue, that's the way databases work. Django doesn't have anything to do with generating ids it just tells the database to insert a row and gets the id in response from database. The id starts at 1 for each table and increments every time you insert a row. Deleting rows doesn't cause the id to go back. You shouldn't usually be concerned with that, all you need to know is that each row has a unique id.
    You can of course change the counter that generates the id for your table with a database command and that depends on the specific database system you're using.

提交回复
热议问题