MySQL
Error 1364
Database Errors
SQL Troubleshooting
Default Values

mysql error 1364 Field doesn't have a default values

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

MySQL error 1364 appears when an insert or update statement does not provide a value for a required column that lacks a default. This is usually a schema and data-contract mismatch, not just a SQL typo. The right fix depends on whether the field is truly required, optional, or should have a business-safe default.

Reproducing the Error

A minimal example makes diagnosis clear.

sql
1CREATE TABLE users (
2  id INT PRIMARY KEY AUTO_INCREMENT,
3  email VARCHAR(255) NOT NULL,
4  name VARCHAR(100) NOT NULL
5);
6
7INSERT INTO users (email) VALUES ('[email protected]');

The insert fails because name is NOT NULL and has no default value.

Fix Option 1: Provide the Missing Column Value

If the column is required by business rules, the safest solution is to always provide it.

sql
INSERT INTO users (email, name)
VALUES ('[email protected]', 'Alice');

At application level, validate payload completeness before SQL generation. Database errors should be fallback protection, not the first validation layer.

Fix Option 2: Add a Default Value

If a meaningful fallback exists, adding a default can remove repetitive insert boilerplate.

sql
ALTER TABLE users
MODIFY name VARCHAR(100) NOT NULL DEFAULT 'Unknown';

Use this only when default value has clear domain meaning. Placeholder defaults can hide data quality issues if abused.

Fix Option 3: Make Column Nullable

If data is optional, model it as nullable rather than forcing empty placeholders.

sql
ALTER TABLE users
MODIFY name VARCHAR(100) NULL;

Then ensure reporting and API logic handle nulls intentionally.

Strict SQL Mode and Error Behavior

Strict mode surfaces this error consistently and is generally preferred for production correctness.

sql
SELECT @@sql_mode;

In less strict modes, MySQL may insert implicit defaults and warn instead of failing. That can silently introduce bad data. For most systems, strict mode plus explicit validation gives safer behavior.

Deployment Pattern for New Required Columns

When adding a new required field to an existing table, avoid immediate hard enforcement.

sql
ALTER TABLE users ADD COLUMN status VARCHAR(20) NULL;
UPDATE users SET status = 'active' WHERE status IS NULL;
ALTER TABLE users MODIFY status VARCHAR(20) NOT NULL;

This phased migration prevents write outages and large rollback risk.

ORM and Migration Alignment

Error 1364 often comes from mismatch between ORM model and actual table schema. Verify:

  • required annotations in model classes
  • migration scripts for defaults and nullability
  • generated SQL includes mandatory columns

Enable SQL logging in development to inspect real insert statements and catch missing fields early.

Diagnostic Checklist

When troubleshooting in production:

  1. inspect table DDL with SHOW CREATE TABLE
  2. identify failing insert or update statement
  3. check SQL mode on that environment
  4. confirm ORM model and migration version
  5. decide required versus optional semantics for missing field
sql
SHOW CREATE TABLE users;

This structured approach avoids quick fixes that damage long-term data integrity.

Data-Contract Governance

Teams that maintain shared schemas should document required field contracts in API specs and migration notes. This reduces accidental field omission during service integration changes. Error 1364 is often a symptom of drift between application payload contracts and database constraints, so contract review is a long-term prevention strategy.

Common Pitfalls

  • Disabling strict mode globally to suppress the error instead of fixing schema or query.
  • Adding meaningless defaults that conceal missing required business data.
  • Treating optional fields as required and inserting placeholder text.
  • Updating schema without updating ORM models and API validation rules.
  • Applying direct production fixes without migration rollback plan.

Summary

  • Error 1364 indicates a required column value is missing and no default is available.
  • Best fix is explicit value insertion when field is truly required.
  • Use defaults only when fallback semantics are valid.
  • Use nullable columns for genuinely optional data.
  • Keep schema, ORM mappings, and SQL mode policy aligned.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.