(I'm new to Django, Python, and Postgresql) I've been adding and deleting data in my development and noticed that the pk keeps adding up and never reset to 1 even if I delete all the models. Is it possible to reset the pk to start from 1 before I push this up to the production? Is it a good idea to do that?
Django reset auto-increment pk/id field for production
·
Answer a question
Answers
You can reset model id sequence using sqlsequencereset command
python manage.py sqlsequencereset myapp1 myapp2 myapp3| psql
If you want to read the generated sql command, just execute that command without pipe it to psql.
python manage.py sqlsequencereset myapp1 myapp2 myapp3
You need use this command over your production database. But, as @knbk mentioned, if your production database is new, you don't need to reset id sequences.
更多推荐

所有评论(0)