duplicate key value violates unique constraint "users_pkey"
Laravel app, just moved from MySQL to PostgreSQL. The full message as Laravel shows it:
Why it happens
You copied rows from MySQL with their ids, but the Postgres sequence behind each id column still starts at 1. The first new insert reuses id 1, 2, 3... If your ids have gaps, it fails some inserts and not others, so it looks random.
Fix
Tested on Postgres 17.11: after the setval, the next insert gets MAX(id)+1. Running it again is safe. If the key column is named differently, change 'id'.
The tested fix for every table at once (scripts, a Laravel command, before/after checks): Laravel Postgres Error Fix Pack ($19), item 01.
Several errors at once? Paste your log into the error matcher. Raw SQL with MySQL syntax: the free SQL translator. Not migrated yet: the free schema risk check finds this kind of problem before the switch. Planning the whole move: Migration Kit ($49, $34.30 with LAUNCH30 until Nov 5).
Other errors after MySQL to Postgres
column "users.name" must appear in the GROUP BY clause or be used in an aggregate functionvalue "3000000000" is out of range for type integeroperator does not exist: boolean = integeroperator does not exist: character varying = integerdate/time field value out of range: "0000-00-00 00:00:00"column "a@x.com" does not existsyntax error at or near "`"function ifnull(text, unknown) does not existinvalid byte sequence for encoding "UTF8": 0x00current transaction is aborted, commands ignored until end of transaction block(no error) search or login finds nothing: WHERE email LIKE ... returns 0 rows