How to fix ERROR 1364: Field doesn't have default value in MySQL
This error occurs when you attempt to INSERT or UPDATE a row in a MySQL table without providing a value for a NOT NULL column that has no default value. It is triggered only when MySQL is running in Strict mode, which enforces data integrity rules.
Quick fix
Fixes 1364
ERROR 1364 (HY000): Field 'user_id' doesn't have a default value- Identify which column is missing a value
- Provide explicit values in your INSERT statement
- Add a DEFAULT value to the column if appropriate
- Use AUTO_INCREMENT for primary key columns
ERROR 1364 (HY000): Field 'user_id' doesn't have a default valueERROR 1364: Field doesn't have default value
What this error means
MySQL Error 1364 (ER_NO_DEFAULT_FOR_FIELD) is a strict mode validation error that prevents data from being inserted into NOT NULL columns without explicit values. When a column is defined as NOT NULL, MySQL requires either a value to be provided during INSERT/UPDATE or a DEFAULT clause to be set at the table level. In Strict mode (STRICT_TRANS_TABLES or STRICT_ALL_TABLES), MySQL converts this validation warning into a fatal error. This protects against accidental data loss and helps maintain referential integrity. Without this error, databases could end up with incomplete or NULL data in columns that should never be empty.
Typical symptoms
- INSERT statement fails with "ERROR 1364" when not providing a value for a specific column
- UPDATE statement fails when omitting a NOT NULL column value
- Application migrations or batch operations abort unexpectedly
- Errors only appear in production but not in local development (different MySQL configurations)
- Third-party tools or frameworks cannot insert data into your table
Common causes
- NOT NULL column without a DEFAULT value is omitted from INSERT statement
- Migration adds a new NOT NULL column without DEFAULT to existing table with data
- Framework or ORM does not provide values for auto-increment or non-nullable fields
- MySQL is running in Strict mode (STRICT_TRANS_TABLES or STRICT_ALL_TABLES)
- Copied INSERT statements from another database with different schema constraints
- Database migrated from permissive to strict MySQL/MariaDB configuration
How to fix "ERROR 1364: Field doesn't have default value"
The error message will specify the exact column name that is causing the issue. For example:
ERROR 1364 (HY000): Field 'user_id' doesn't have a default valueExamine your INSERT statement and check if you are omitting this column. Most commonly this happens with auto-increment ID columns or status fields.
The simplest solution is to include a value for every NOT NULL column in your INSERT statement:
-- Before (causes error)
INSERT INTO users (name, email) VALUES ('John', 'john@example.com');
-- After (works correctly)
INSERT INTO users (id, name, email, status) VALUES (1, 'John', 'john@example.com', 'active');If the column is an auto-increment field, you can omit it if it is truly AUTO_INCREMENT. Otherwise, provide the value explicitly.
For columns that should have a sensible default, use ALTER TABLE to add a DEFAULT clause:
ALTER TABLE users MODIFY COLUMN status VARCHAR(50) NOT NULL DEFAULT 'pending';ALTER TABLE products MODIFY COLUMN created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;This allows INSERT statements to omit the column, and MySQL will use the default automatically. Only use defaults when a logical fallback value exists.
If the offending column is an ID field, ensure it is properly configured with AUTO_INCREMENT:
ALTER TABLE users MODIFY COLUMN id INT NOT NULL AUTO_INCREMENT;Once AUTO_INCREMENT is set, you can omit the id column from INSERT statements and MySQL will generate unique values automatically:
INSERT INTO users (name, email) VALUES ('Jane', 'jane@example.com');
-- id will be auto-generated (1, 2, 3, etc.)If the column does not truly require a value in all cases, change it to allow NULL:
ALTER TABLE orders MODIFY COLUMN notes VARCHAR(500) NULL;Then INSERT statements can omit this column or explicitly set it to NULL:
INSERT INTO orders (id, customer_id) VALUES (1, 100);
-- notes will be NULLUse this approach carefully—only when NULL is semantically correct for that field.
Advanced notes
MySQL Strict Mode: Error 1364 only occurs when MySQL is running in Strict mode (STRICT_TRANS_TABLES or STRICT_ALL_TABLES). In permissive mode, the same INSERT would succeed but MySQL would insert the column's implicit default (0 for numbers, empty string for text). If you must disable Strict mode, edit your MySQL configuration file (my.cnf or my.ini) and set sql_mode="" under the [mysqld] section. However, this is discouraged as it weakens data integrity checks.
Framework Implications: Many frameworks (Laravel, Django, Rails) handle auto-increment fields implicitly. If you are using an ORM, ensure you are not explicitly providing NULL or omitting required columns. Consult your framework's documentation for the correct way to define models.
Schema Design Best Practice: Always define NOT NULL columns with either a sensible DEFAULT or use AUTO_INCREMENT for ID columns. This prevents this error class entirely. When adding NOT NULL columns to existing tables, provide a DEFAULT value or a backfill migration to populate existing rows.
Frequently asked questions
- What does "1364" mean?
- MySQL Error 1364 (ER_NO_DEFAULT_FOR_FIELD) is a strict mode validation error that prevents data from being inserted into NOT NULL columns without explicit values. When a column is defined as NOT NULL, MySQL requires either a value to be provided during INSERT/UPDATE or a DEFAULT clause to be set at the table level. In Strict mode (STRICT_TRANS_TABLES or STRICT_ALL_TABLES), MySQL converts this validation warning into a fatal error.
- How do I fix "1364"?
- This error occurs when you attempt to INSERT or UPDATE a row in a MySQL table without providing a value for a NOT NULL column that has no default value. It is triggered only when MySQL is running in Strict mode, which enforces data integrity rules.
- What causes "1364"?
- NOT NULL column without a DEFAULT value is omitted from INSERT statement Migration adds a new NOT NULL column without DEFAULT to existing table with data Framework or ORM does not provide values for auto-increment or non-nullable fields
- Is the "1364" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚MySQL Official Documentation
- 📖MySQL Error Reference Documentation(Official Docs)
- 🐙