MySQL error 1364: Field doesn't have a default value
An INSERT left out a NOT NULL column that has no default. In strict mode that's an error; name the column or give it a default.
- Error number
1364- Name
ER_NO_DEFAULT_FOR_FIELD- SQLSTATE
HY000- Category
- Data values
What it means
When an INSERT omits a column, MySQL uses the column's default. A NOT NULL column without a DEFAULT has none to use. In strict SQL mode (the default since 5.7) the insert fails with 1364; in non-strict mode MySQL inserts the type's implicit default (0, '' or a zero date) with a warning.
Common causes
- Adding a
NOT NULLcolumn without a default and not updating the code that inserts rows. - An application tested on a server with strict mode off, deployed to one with it on.
- Expecting an
idcolumn to fill itself when it isn'tAUTO_INCREMENT.
How to fix it
-
Include the column in the insert.
INSERT INTO orders (customer_id, status) VALUES (42, 'new');
-
Or give it a default.
ALTER TABLE orders MODIFY status VARCHAR(20) NOT NULL DEFAULT 'new';
-
If the column is meant to be generated, make it
AUTO_INCREMENTor a generated column. Avoid turning off strict mode to hide the error; it hides data errors too.
Related errors
More data values errors
1366Incorrect value for column1406Data too long for column1292Truncated incorrect value1264Out of range value for column1265Data truncated for column
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.