// MySQL error reference

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
Error message
Field '%s' doesn't have a default value

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 NULL column 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 id column to fill itself when it isn't AUTO_INCREMENT.

How to fix it

  1. Include the column in the insert.

    INSERT INTO orders (customer_id, status) VALUES (42, 'new');
  2. Or give it a default.

    ALTER TABLE orders MODIFY status VARCHAR(20) NOT NULL DEFAULT 'new';
  3. If the column is meant to be generated, make it AUTO_INCREMENT or a generated column. Avoid turning off strict mode to hide the error; it hides data errors too.

Related errors

More data values errors

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.

// fewer errors, faster fixes

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.