Home > php教程 > PHP开发 > Summary of Django common problems and solutions

Summary of Django common problems and solutions

高洛峰
Release: 2016-11-23 13:05:45
Original
1175 people have browsed it

1. Django + PostgreSQL: How to reset primary key?

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

This is used in clearing tables After the data, the pk of the data does not increase from 1, and the method of resetting the sequence to 1 is used.

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;


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template