MySQL ERROR 1406: Data too long for column
The value is longer than the column allows (e.g. 300 characters into VARCHAR(255)), and strict mode rejects it instead of truncating.
Meaning
With STRICT_TRANS_TABLES (default since MySQL 5.7), oversize values raise 1406. Without strict mode MySQL silently truncated them — so moving to a new server can make old code fail.
Common causes
- Input longer than the column definition
- Multi-byte characters exceeding byte limits in older setups
- Column too small for real-world data (URLs, user agents, names)
- ENUM/SET value not in the list (related 1265 warning)
⚡ Quick fix
- Validate/limit length in the application
- Widen the column (
VARCHAR(2048)orTEXT) - Don’t disable strict mode — it protects data integrity
Detailed fix by platform
MySQL
- Widen the column:sql
ALTER TABLE visits MODIFY user_agent VARCHAR(512) NOT NULL DEFAULT '';
PHP
- Trim before insert:
mb_substr($ua, 0, 512)and validate max lengths in forms.
How to diagnose
- Column — Defined length vs actual value length
- Mode — SELECT @@sql_mode — strict?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026