Django reset auto-increment pk/id field for production

后端 未结 2 1480
孤城傲影
孤城傲影 2021-01-02 15:09

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

2条回答
  •  孤独总比滥情好
    2021-01-02 16:01

    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.

提交回复
热议问题