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.
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.
MySQL Error Code: 1364
Official name: Field Doesn't Have a Default Value
Service: MySQL
Field '%s' doesn't have a default value
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.
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])
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')
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");
}
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.
The message names the field; check why it is absent from your INSERT.
This page documents fixes for: nodejs-mysql2, python-sqlalchemy, php-pdo.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official MySQL documentation linked below and adds practical troubleshooting guidance on top.