Data too long for column
ER_DATA_TOO_LONG (1406) is returned in strict mode when an INSERT or UPDATE supplies a string value longer than the column's defined length. Without strict mode this would silently truncate.
CREATE TABLE t (name VARCHAR(10) NOT NULL);
INSERT INTO t VALUES ('this is much too long for the column');expected output
ERROR 1406 (22001): Data too long for column 'name' at row 1
Fix 1
Truncate at the application layer
WHEN The full value is not required.
-- Python/application:
name = name[:10] # truncate to column length
-- SQL:
INSERT INTO t VALUES (LEFT('long value here', 10));Why this works
LEFT(str, n) truncates the string to n characters at the SQL layer.
Fix 2
Increase the column length
WHEN The full value must be preserved.
ALTER TABLE t MODIFY name VARCHAR(255);
Why this works
Widening the column definition accommodates the full value.
✕ Disable strict mode to allow silent truncation
Silently truncated data causes subtle data loss bugs that are very hard to debug after the fact.
MySQL 8.0 — 1406 ER_DATA_TOO_LONG
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev