invalid byte sequence for encoding "UTF8": 0x00

Laravel app, just moved from MySQL to PostgreSQL. The full message as Laravel shows it:

SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0x00

Why it happens

Some MySQL text values contain NUL bytes (often from binary data or bad imports). Postgres text can't store them, so the load fails.

Fix

-- on MySQL, find and strip them before copying: SELECT id FROM t WHERE INSTR(name, CHAR(0)) > 0; UPDATE t SET name = REPLACE(name, CHAR(0), '') WHERE INSTR(name, CHAR(0)) > 0;

Silent variant: through PHP's pdo_pgsql (PHP 8.4, Postgres 17), a bound value 'a\0b' was stored as 'a' with no error. Everything after the NUL is lost. Check before you copy. Tested on MariaDB 11.8 and Postgres 17.

More fixes like this one, as tested scripts: Laravel Postgres Error Fix Pack ($19).

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

Published with deed.page