Firstly, run these 2 commands, be aware of Capitalize:
SELECT MAX("Id") FROM "TableName"; -- column Id is the primary key of table TableName, which is autoincrement SELECT nextval(pg_get_serial_sequence('"TableName"', 'Id'));
For unknown reason, the result of the first query is greater then the second one. That cause the next inserted record will be duplicate with the exist value.
To fix that, just need to re-generate the auto increment value by this command:
SELECT setval(pg_get_serial_sequence('"TableName"', 'Id'), coalesce(max("Id") + 1, 1), false) FROM "TableName";