How do I reset autoincrement for id(default field for models in django) after deleting all records in django?
Asked
Active
Viewed 1,766 times
0
-
Does this answer your question? [Django model instances primary keys do not reset to 1 after all instances are deleted](https://stackoverflow.com/questions/27735375/django-model-instances-primary-keys-do-not-reset-to-1-after-all-instances-are-de) – oruchkin Jun 19 '22 at 17:19
-
2Better to not rely on ids having specific values. – snakecharmerb Jun 19 '22 at 18:25
1 Answers
0
I also encounter this one, especially if I really need the id of the record to go back at one.
What I always do was restart my whole database (delete or drop the database and run the migrate command)
But this will be problematic once you already have hundreds of data for you have to input it again.
Instead you can try the answers from this question posted also here in StackOverflow Django reset auto-increment pk/id field for production

juanjuan
- 1
- 1
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 20 '22 at 01:55