MySQL error 1406: Data too long for column
A string or binary value is longer than the column allows, for example 300 characters into VARCHAR(255). Widen the column or shorten the value.
- Error number
1406- Name
ER_DATA_TOO_LONG- SQLSTATE
22001- Category
- Data values
What it means
The value exceeds the column's declared length (in characters for text types, bytes for binary types). In strict mode the statement fails with 1406 and names the column and row. In non-strict mode MySQL truncates the value and only warns (1265).
Common causes
- User input longer than the column, such as a long name or URL.
- A
VARCHARsized for single-byte data that now holds longer text. - Inserting into a
TEXTcolumn more than its 65,535-byte limit (useMEDIUMTEXT). - A
BITorBINARYcolumn given more bits or bytes than it holds.
How to fix it
-
Find the longest value you need to store, then widen the column.
ALTER TABLE customers MODIFY website VARCHAR(2048);
-
Or validate and shorten values in the application before inserting.
Reproduce it safely
CREATE TEMPORARY TABLE t (code VARCHAR(3));
INSERT INTO t VALUES ('ABCD'); -- ERROR 1406 (22001): Data too long for column 'code' at row 1
Related errors
1265Data truncated for column1366Incorrect value for column8152SQL Server: String or binary data truncated2628SQL Server: Truncated in table, column22001PostgreSQL: value too long for typeORA-12899Oracle: value too large for column
More data values errors
1364Field doesn't have a default value1292Truncated incorrect value1264Out of range value for column1067Invalid default value
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.