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

前端 未结 7 757
说谎
说谎 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:38

    Did you actually drop them from your database or did you delete them using Django? Django won't change AUTO_INCREMENT for your table just by deleting rows from it, so if you want to reset your primary keys, you might have to go into your db and:

    ALTER TABLE  AUTO_INCREMENT = 1;
    

    (This assumes you're using MySQL or similar).

提交回复
热议问题