Menu

MySQL Error 1364: Field Doesn't Have a Default Value

Fix MySQL Error 1364 by supplying a required column value or defining an appropriate default; check strict SQL mode and the table schema.

Posted on By
On this page

MySQL Error 1364 (HY000, ER_NO_DEFAULT_FOR_FIELD) means an INSERT or REPLACE omitted a column that requires a value and has no default. With strict SQL mode enabled, MySQL rejects the row rather than silently filling an implicit value. See the MySQL error reference and data type default rules.

Example: a required column has no default

CREATE TABLE orders (
  order_id INT AUTO_INCREMENT PRIMARY KEY,
  customer_id INT NOT NULL,
  status VARCHAR(20) NOT NULL
);

This insert omits status, so MySQL reports Error 1364:

INSERT INTO orders (customer_id)
VALUES (42);

Check both the table definition and the SQL mode used by the current connection:

SHOW CREATE TABLE orders;
SELECT @@SESSION.sql_mode;

MySQL 8.4 enables strict SQL mode by default, but server and session settings can differ. See MySQL SQL modes.

Fix the insert or the column definition

Supply a value for the required field

If each order must have a status, include it in the insert:

INSERT INTO orders (customer_id, status)
VALUES (42, 'pending');

Add a default only when the value is truly implied

If new orders should start with the same valid status, define that default:

ALTER TABLE orders
  ALTER COLUMN status SET DEFAULT 'pending';

The original insert can then omit status; new rows use 'pending'. Choose a default that matches the application’s data rules, rather than adding one only to suppress the error.

Allow NULL only when the field is optional

If the order may genuinely have no status yet, change the column to allow NULL. See the MySQL NOT NULL guide for the schema trade-off.

  • Error 1364: a required column was omitted and has no default while strict mode is active.
  • Error 1048: the statement explicitly supplied NULL for a NOT NULL column. See the MySQL NOT NULL tutorial.
  • Error 1136: the number of values does not match the number of target columns. See MySQL Error 1136.

Do not disable strict SQL mode as a routine fix: MySQL can then supply implicit defaults that hide missing application data. Use an explicit value, a valid schema default, or a nullable column when the field is truly optional. For standard INSERT column-list and DEFAULT syntax, see MySQL INSERT.