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

MySQL error 1364 (Field Doesn't Have a Default Value) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

MySQL Error Code 1364 MySQL Last verified 2026-08-19

Quick Answer

The message names the field; check why it is absent from your INSERT. If that does not apply, provide the value in the application/query — the full checklist is below.

Error Code

MySQL Error Code: 1364
Official name: Field Doesn't Have a Default Value
Service: MySQL

What does this error mean?

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

Common Causes

How to Fix

  1. The message names the field; check why it is absent from your INSERT
  2. Provide the value in the application/query
  3. If the column should have a fallback, add a DEFAULT: `ALTER TABLE t ALTER col SET DEFAULT 'x';`
  4. Confirm strict mode: `SELECT @@sql_mode;` — STRICT_TRANS_TABLES makes this an error by design
  5. When adding a required column to an existing table, backfill rows first or use a DEFAULT

Code Examples

Check strict mode sql
SELECT @@sql_mode;
-- contains STRICT_TRANS_TABLES: missing fields become hard errors

Explains why a missing value errors instead of warning; removing strict mode is a last resort.

Framework-Specific Fixes

nodejs-mysql2

Default the field at the application layer so inserts never omit it.

const user = { email, role: role || 'member', created_at: new Date() }
await pool.query('INSERT INTO users SET ?', [user])
python-sqlalchemy

Set server_default on the column so the DB fills it when the app does not.

class User(Base):
    __tablename__ = 'users'
    role = Column(String(20), server_default='member')
php-pdo

Build INSERT column lists from validated input arrays, never from partial data.

$required = ['email', 'name'];
foreach ($required as $f) {
  if (!isset($data[$f])) throw new InvalidArgumentException("$f missing");
}

You Might Also Like

Frequently Asked Questions

Why am I seeing MySQL error 1364?

Most often this happens when inserting a row without a value for a NOT NULL column that has no DEFAULT, or when strict SQL mode (default since MySQL 5.7) turns this from a warning into an error.

How do I fix MySQL error 1364?

The message names the field; check why it is absent from your INSERT.

Which frameworks have documented fixes for error 1364?

This page documents fixes for: nodejs-mysql2, python-sqlalchemy, php-pdo.

Official Sources

This page is based on the official MySQL documentation linked below and adds practical troubleshooting guidance on top.