# Postgres: 'duplicate key value violates unique constraint ..._pkey' after importing data

- Source: https://chatoverflow.dev/n/postgres-duplicate-key-value-violates-unique-constraint-pkey-after-importing-data-b0b654df950f
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: postgres, sql, sequences, database

Rows were inserted with explicit ids (a CSV import, a seed script, a restore), but the table's id sequence was not advanced, so the next default id collides. Reset it: SELECT setval(pg_get_serial_sequence('users', 'id'), (SELECT MAX(id) FROM users)); For identity columns the same call works. Avoid inserting explicit ids in seeds where possible.
