Field doesn't have a default value
Production Risk
HIGH — inserts fail in strict mode; silent data corruption in non-strict mode.
Error 1364 (SQLSTATE HY000) is returned when an INSERT statement omits a column that is NOT NULL and has no DEFAULT value. In strict SQL mode (STRICT_TRANS_TABLES) this is a hard error; in non-strict mode it may generate a warning and insert the implicit default for the type.
- 1INSERT statement omits a required NOT NULL column with no DEFAULT
- 2Application code does not include all required fields in the INSERT
- 3Schema changed (column added as NOT NULL with no DEFAULT) but application was not updated
Inserting a row without a required column.
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
department VARCHAR(50) NOT NULL -- no DEFAULT
);
INSERT INTO employees (name) VALUES ('Ana');
-- 'department' is requiredexpected output
ERROR 1364 (HY000): Field 'department' doesn't have a default value
Fix 1
Include the missing column in the INSERT
WHEN When the value is known at insert time.
INSERT INTO employees (name, department) VALUES ('Ana', 'Engineering');Why this works
Always list all NOT NULL columns without defaults explicitly in INSERT statements.
Fix 2
Add a DEFAULT value to the column
WHEN When a sensible default exists for the column.
ALTER TABLE employees MODIFY department VARCHAR(50) NOT NULL DEFAULT 'Unassigned';
Why this works
Adding a DEFAULT allows INSERT statements that omit the column to succeed.
Fix 3
Make the column nullable
WHEN When the value may legitimately be unknown at insert time.
ALTER TABLE employees MODIFY department VARCHAR(50) NULL DEFAULT NULL;
Why this works
Nullable columns accept NULL when omitted from an INSERT, which is semantically cleaner than a sentinel default like 'Unassigned'.
✕ Disable strict mode to suppress this error
Non-strict mode inserts implicit type defaults (empty string, 0) that corrupt data.
MariaDB Server error code 1364 / ER_NO_DEFAULT_FOR_FIELD
MariaDB INSERT ↗MariaDB NOT NULL Constraint ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev