1406
MySQLERRORCommonData IntegrityHIGH confidence

Data too long for column

What this means

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.

How to reproduce
trigger — this will error
trigger — this will error
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.

Truncate at the application layer
-- 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.

Increase the column length
ALTER TABLE t MODIFY name VARCHAR(255);

Why this works

Widening the column definition accommodates the full value.

What not to do

✕ Disable strict mode to allow silent truncation

Silently truncated data causes subtle data loss bugs that are very hard to debug after the fact.

Sources
Official documentation ↗

MySQL 8.0 — 1406 ER_DATA_TOO_LONG

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors