欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

Django 常见问题及解决方案汇总

程序员文章站 2022-04-10 14:26:33
...
1. Django + PostgreSQL: How to reset primary key?

http://*.com/questions/544791/django-postgresql-how-to-reset-primary-key

这个是用于在清除表中数据后,数据的 pk 不从1开始增长,将序列重新设置为1的方法。

In your app directory try this:

python manage.py help sqlsequencereset

Pipe it into psql like this to actually run the reset:

python manage.py sqlsequencereset myapp1 myapp2 | psql

Edit: here's an example of the output from this command on one of my tables:

BEGIN;

SELECT setval('"project_row_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "project_row";

COMMIT;

相关标签: Django