How do I fix "duplicate key value violates unique constraint" on the primary key in PostgreSQL?
After an import or migration, every insert collides with an existing id because the sequence is behind. Reset one or all sequences, and prevent it with identity columns.
In this article
- 01Why it happens
- 02Check it
- 03Fix one table
- 04Fix every table at once
· 6 min read
