Struggling with “General error: 1364 Field ‘id’ doesn’t have a default value”? Here’s the clearest guide with real causes, fixes, SQL commands, and Laravel tips. Our Laravel Live Support Team is always here to help you.


If you’ve been building with MySQL or Laravel for a while, you’ve probably bumped into the dreaded General error: 1364 Field ‘id’ doesn’t have a default value at the worst possible moment. It usually appears right when you expect a table to behave, and instead it refuses to accept new rows. Although this issue looks intimidating, the real cause is almost always one overlooked setting: the id column isn’t auto-incrementing.

General error: 1364 Field 'id' doesn't have a default value

Why This Error Happens

To understand it better, you should know that MySQL expects the id column (the primary key in most tables) to either auto-increment or receive a value during insertion. But if neither happens, this exact error shows up. And because many developers rely on Laravel to insert records automatically, even a small mismatch between the table structure and the ORM creates issues.

Enable AUTO_INCREMENT on the id Field

Most of the time, the id field is missing the AUTO_INCREMENT attribute. Even though the column might be marked as PRIMARY and NOT NULL, MySQL won’t generate values for it unless auto-increment is explicitly enabled.

ALTER TABLE migrations MODIFY id INTEGER NOT NULL AUTO_INCREMENT;

If your table contains entries with value 0, change those to unique numbers first. After that, set the next auto-increment value:

SET @new_index = (SELECT MAX(id) FROM migrations );
SET @sql = CONCAT('ALTER TABLE migrations AUTO_INCREMENT = ', @new_index);
PREPARE st FROM @sql;
EXECUTE st;

This solves most occurrences of General error: 1364 Field ‘id’ doesn’t have a default value.

Make Required Fields Nullable or Add Defaults

You might still face the error when other fields in your migration demand values. For example, a name field set as required will interrupt the insert process. To avoid that, adjust your migration:

$table->string('name')->nullable();

or:

$table->string('name')->default('');

Then run:

php artisan migrate:fresh

Correct Your Model’s $fillable Settings

Laravel may block mass assignment if a field such as user_id is inside $guarded. Move it into $fillable instead:

protected $fillable = [
'user_id',
'name',
'detail',
'image',
'color',
'logo'
];

This resolves many hidden triggers of General error: 1364 Field ‘id’ doesn’t have a default value.

Fix Your Database Errors Today!

Chat animation


Update Manually Created Tables

If you built the table manually and forgot the auto-increment flag, here’s the exact command:

ALTER TABLE `table_name` CHANGE `id` `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;

Although some developers try to disable MySQL strict mode, that should always be the last option. The correct fix is to configure the table properly instead of bypassing database rules.

Conclusion

In the end, the message General error: 1364 Field ‘id’ doesn’t have a default value looks complex only until you know where to check. Once you find the root cause, the fix is simple and it saves hours of debugging that nobody wants on their plate.