Django reset auto-increment pk/id field for production

浪子不回头ぞ 提交于 2020-05-10 14:11:10

问题


(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?


回答1:


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.



来源:https://stackoverflow.com/questions/32531677/django-reset-auto-increment-pk-id-field-for-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!