Postgres Duplicate Key Value Violates Unique Constraint
Execute two commands and compare the returned values.
SELECT MAX(id) FROM table_name;
and
SELECT nextval('table_name_id_seq');
If the first value is greater than the second, run the following command.
SELECT setval('table_name_id_seq', (SELECT MAX(id) FROM table_name));