Common SQL Errors

MySQL Error 1364: ER_NO_DEFAULT_FOR_FIELD - How to Fix and Prevent

Galaxy Team
August 6, 2025

<p>Raised when an INSERT or UPDATE omits a value for a NOT NULL column that lacks a DEFAULT clause.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1364?

<p>MySQL Error 1364: ER_NO_DEFAULT_FOR_FIELD occurs when you insert or update a table but skip a NOT NULL column without a default value. Supply the missing value, add a DEFAULT clause, or relax the constraint to resolve the problem.</p>

Error Highlights

Typical Error Message

Field '%s' doesn't have a default value

Error Type

Data Integrity Error

Language

MySQL

Symbol

ER_NO_DEFAULT_FOR_FIELD

Error Code

1364

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1364?

MySQL raises error 1364 ER_NO_DEFAULT_FOR_FIELD when an INSERT or UPDATE statement omits a value for a column declared NOT NULL with no DEFAULT clause. The server halts the statement to protect data integrity.

The error commonly appears after schema changes, during bulk loads, or when moving from permissive sql_mode settings to STRICT_ALL_TABLES or STRICT_TRANS_TABLES.

What causes this error?

The storage engine validates every column before writing a row. If a NOT NULL column lacks both an explicit value and a defined default, error 1364 fires. Strict modes turn what was once a warning into a full error.

Developers often encounter the issue after adding new NOT NULL columns without backfilling existing rows or when relying on timestamp columns created without DEFAULT CURRENT_TIMESTAMP in older MySQL versions.

How to fix MySQL Error 1364

The quickest fix is to supply a value for every NOT NULL column in your INSERT or UPDATE. Alternatively, add a DEFAULT clause or change the column to allow NULL if that aligns with business rules. Disabling strict mode is possible but discouraged in production.

Common scenarios and solutions

Adding a new NOT NULL flag column requires either a DEFAULT value or an immediate UPDATE to populate existing rows. Bulk CSV imports commonly fail because optional columns are omitted; include placeholders or define sensible defaults.

Best practices to avoid this error

Create new columns as NULLABLE, backfill data, then convert them to NOT NULL with a DEFAULT. Use CI checks and linters to catch missing defaults. Galaxy's schema-aware autocomplete surfaces NOT NULL constraints, helping you catch omissions before running queries.

Related Errors and Solutions

Error 1048 Column cannot be null shows when you explicitly insert NULL. Error 1366 Incorrect integer value occurs when provided data fails type validation. Both signal data quality issues; fix them by validating input and aligning constraints.

Common Causes

Missing value in INSERT

An INSERT statement omits a mandatory column that has no default.

New NOT NULL column without DEFAULT

A schema change introduces a NOT NULL column but existing rows lack data.

Strict SQL mode enabled

STRICT_ALL_TABLES or STRICT_TRANS_TABLES converts warnings into errors.

Implicit timestamp columns

Older tables rely on auto-filled timestamps yet lack DEFAULT CURRENT_TIMESTAMP.

Related Errors

Error 1048 column cannot be null

Occurs when a NULL is explicitly inserted into a NOT NULL column.

Error 1366 incorrect integer value

Raised when a string fails to convert to an integer under strict mode.

Error 1292 truncated incorrect datetime value

Happens when a date string does not match the column format.

FAQs

Can I ignore error 1364?

Ignoring the error risks inserting incomplete data. Always resolve the root cause by providing values or defaults.

Does sql_mode affect this error?

Yes. STRICT_TRANS_TABLES and STRICT_ALL_TABLES escalate missing defaults from warnings to errors, triggering 1364.

How does Galaxy help avoid error 1364?

Galaxy highlights NOT NULL constraints in its autocomplete and warns when required columns are absent from your INSERT statement.

Is adding a default always safe?

Add defaults only when a sensible fallback exists. Otherwise require explicit values to safeguard data accuracy.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo