MySQL Error: 'ERROR 1067 (42000): Invalid default value' — Cause, Fix, and Troubleshooting Guide
Fix MySQL ERROR 1067 (42000) Invalid default value: zero dates under strict sql_mode, DEFAULT on TEXT/BLOB, and CURRENT_TIMESTAMP limits.
- #mysql
- #mariadb
- #database
- #troubleshooting
Stuck on this MySQL error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
Overview
ERROR 1067 (42000) is raised at DDL time when a column’s DEFAULT clause is not legal for that column’s type under the server’s current sql_mode:
ERROR 1067 (42000): Invalid default value for 'created_at'
The most common trigger is a DATE/DATETIME/TIMESTAMP column defaulting to a zero date like '0000-00-00 00:00:00' on a server running NO_ZERO_DATE/NO_ZERO_IN_DATE/STRICT_TRANS_TABLES — the defaults on MySQL 5.7+ and 8.0. A dump created on an older, permissive server fails to import on a strict one.
Symptoms
- A
CREATE TABLEorALTER TABLEfails, always naming one column. - A schema/dump that imported fine on MySQL 5.6 fails on 5.7/8.0.
- ORM auto-migrations fail after a MySQL upgrade.
- The column is a date/time, or a
TEXT/BLOB/JSONcolumn with a literal default.
Common Root Causes
1. Zero-date default under strict sql_mode
CREATE TABLE events (
id INT PRIMARY KEY,
created_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
);
ERROR 1067 (42000): Invalid default value for 'created_at'
NO_ZERO_DATE (on by default) forbids the all-zero placeholder.
2. A literal DEFAULT on TEXT / BLOB / JSON / GEOMETRY
Before MySQL 8.0.13 these types cannot have a literal default at all; a DEFAULT '' on a TEXT column raises 1067.
3. DEFAULT CURRENT_TIMESTAMP on the wrong type
On older MySQL only TIMESTAMP (and later DATETIME) accept DEFAULT CURRENT_TIMESTAMP; using it on a DATE or INT fails.
4. Default value out of range for the type
TINYINT with DEFAULT 999, or an ENUM default that is not one of the listed members.
How to diagnose
Check the active sql_mode — it dictates which defaults are legal:
SELECT @@GLOBAL.sql_mode, @@SESSION.sql_mode;
+------------------------------------------------------------------+
| @@SESSION.sql_mode |
+------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_... |
+------------------------------------------------------------------+
Inspect the offending column’s type and version:
SELECT VERSION();
SHOW CREATE TABLE events\G
Fixes
Prefer fixing the schema over loosening sql_mode. For timestamps, use a real default or make the column nullable:
CREATE TABLE events (
id INT PRIMARY KEY,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
For TEXT/BLOB on older servers, drop the literal default (the column is implicitly nullable) or upgrade to 8.0.13+ where DEFAULT (expression) is allowed:
ALTER TABLE notes MODIFY body TEXT NULL;
If you must import a legacy dump unchanged, relax the mode for that session only:
SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';
-- run the import, then restore strict mode
Persisting a relaxed mode (last resort) in my.cnf:
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
What to watch out for
- Removing
NO_ZERO_DATEglobally to force an old dump through re-introduces zero-date bugs across the whole server — scope any relaxation to the import session. CURRENT_TIMESTAMPas a default only works onTIMESTAMP/DATETIME; do not paste it ontoDATEcolumns.- Application-level “empty date” conventions (
0000-00-00) should becomeNULL; update code that reads those rows before migrating. - After a major-version upgrade, dry-run your migrations against the new server — 1067 surfaces at deploy time otherwise.
Related
- ERROR 1064: SQL syntax error — the general DDL/DML parse-error you will also hit while editing schema.
- ERROR 1292: Incorrect datetime value — the runtime counterpart when inserting bad dates under strict mode.
- ERROR 1055: only_full_group_by — another strict-
sql_modebehavior change that breaks legacy schemas.
Fixed it? Get 500 MySQL & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Did this fix your issue?
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.