Migration errors
Fix: ERROR — value too long for type character varying(n)
ERROR: value too long for type character varying(255) When it happens
Loading data into a PostgreSQL table — often right after converting a MySQL schema, when a VARCHAR column receives a string longer than its declared length.
Why it happens
PostgreSQL enforces character varying(n) strictly: a value longer than n characters is rejected, never silently shortened. MySQL outside strict mode quietly truncates overlong values and only warns, so the source column's declared length was never actually enforced. When that same data lands in PostgreSQL, the real (longer) strings finally overflow.
How to fix it
1. Find how long the data really is
SELECT max(char_length(notes)) FROM t; Compare the result against the column's declared length to pick a safe new size.
2. Widen the column to fit
ALTER TABLE t ALTER COLUMN notes TYPE varchar(2000); 3. Or drop the length cap entirely
ALTER TABLE t ALTER COLUMN notes TYPE text; In PostgreSQL text and varchar are equally fast — an arbitrary length limit buys you nothing here, so plain text is usually the right call.
4. Converting from MySQL with us?
Our converter preserves your declared VARCHAR lengths but maps unbounded MySQL TEXT/LONGTEXT to PostgreSQL text, so columns that held truncated data keep loading instead of overflowing.
Migrating between MySQL and PostgreSQL?
Our converter handles this and dozens of other gotchas automatically — upload a dump, download working SQL.
Try the converter free