IntegrityError duplicate key value violates unique constraint – django/postgres

This happend to me – it turns out you need to resync your primary key fields in Postgres. The key is the SQL statement:

SELECT setval('tablename_id_seq', (SELECT MAX(id) FROM tablename)+1);

Leave a Comment