duplicate key value violates unique constraint

Correcting the ERROR error: duplicate key value violates unique constraint.

The problem occurs when migrating / importing data. PostgreSQL stops understanding columns and wants to create another value to the unique column.

Let’s find the maximum number according to PostgreSQL:

SELECT MAX (id) FROM categories_done;
SELECT nextval (‘categories_id_seq’);

Let’s reset the counter:

SELECT setval (‘categories_id_seq’, (SELECT MAX (id) FROM categories) +1);

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *