1364
MariaDBERRORCommonData IntegrityHIGH confidence

Field has no default value

What this means

ER_NO_DEFAULT_FOR_FIELD (1364) is returned when an INSERT omits a column that has no DEFAULT value and is not nullable. Strict SQL mode (enabled by default in MySQL 5.7.5+) makes this a hard error rather than a warning.

How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE orders (
  id INT AUTO_INCREMENT PRIMARY KEY,
  customer_id INT NOT NULL  -- no DEFAULT
);
INSERT INTO orders VALUES ();  -- omits customer_id

expected output

ERROR 1364 (HY000): Field 'customer_id' doesn't have a default value

Fix 1

Provide the required column in INSERT

WHEN The column must always have a value.

Provide the required column in INSERT
INSERT INTO orders (customer_id) VALUES (42);

Why this works

Explicitly supplying the column value satisfies the NOT NULL / no-default constraint.

Fix 2

Add a DEFAULT to the column

WHEN A sensible default exists.

Add a DEFAULT to the column
ALTER TABLE orders
  MODIFY customer_id INT NOT NULL DEFAULT 0;

Why this works

A DEFAULT value allows INSERT to omit the column without error.

What not to do

Disable strict SQL mode to suppress the error

Strict mode catches data integrity problems at write time. Disabling it allows silent data truncation and silently wrong values to enter the database.

Version notes
MySQL 5.7.5+

STRICT_TRANS_TABLES is included in sql_mode by default. Earlier versions issued a warning instead of an error.

Sources
Official documentation ↗

MySQL 8.0 — 1364 ER_NO_DEFAULT_FOR_FIELD

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors