# SQLSTATE[HY000]: General error: 1364 Field doesn't have a default value

An insert left out a NOT NULL column that has no default. Pass the value, check that the model lets it through, or make the column nullable or defaulted.

Message:

```text
SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value
```

Exception:

```text
Illuminate\Database\QueryException
```

## What it means

The insert did not include a value for a column that is `NOT NULL` and has no `DEFAULT`, so MySQL refused the row. The message names the column; the SQL in the full message lists the columns the insert did send.

## Why it happens

- The code never sets the column. `DB::table('posts')->insert(['title' => 'Hello'])` on a table with a required `user_id` fails this way.
- The value was passed but Eloquent dropped it. With `#[Fillable(['title'])]` on the model, `Post::create(['user_id' => 1, 'title' => 'Hello'])` silently discards `user_id`, and the insert that reaches MySQL holds only `title` and the timestamps. The [mass assignment guide](/error-guides/laravel-mass-assignment-fillable) explains how Eloquent decides.
- A column was added later without `nullable()` or `default()`. The migration itself runs fine: MySQL fills the existing rows with an empty string for a `string` column, or `0` for an integer. The first insert after the deploy that does not set the new column fails.

MySQL raises this error in strict SQL mode, which Laravel turns on through `'strict' => true` in the default `config/database.php`. Turning it off is not a fix. With `'strict' => false`, MySQL stores the type's implicit default instead: `0` for a number, an empty string for text. In the test, the post with the dropped `user_id` then failed on the foreign key as `1452 Cannot add or update a child row`, and a missing `title` was saved as an empty string without any error.

## How to fix it

Set the value. For a parent like the user, create the row through the relationship, which fills the foreign key for you. This assumes a `posts()` has-many relation on `User` and a `$validated` array from your request validation:

```php
$post = $request->user()->posts()->create([
    'title' => $validated['title'],
]);
```

If the value really comes from the input, list the attribute as fillable on the model:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;

#[Fillable(['title', 'category_id'])]
class Post extends Model
{
}
```

During development, make dropped attributes throw instead of vanishing, in the `boot` method of `AppServiceProvider`:

```php
use Illuminate\Database\Eloquent\Model;

Model::preventSilentlyDiscardingAttributes($this->app->isLocal());
```

If the column may be empty, or has a sensible default, say so in a new migration. Changing a column needs `->change()`, which drops every modifier you leave out, so repeat the ones the column should keep:

```php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::table('posts', function (Blueprint $table) {
    $table->string('slug')->nullable()->change();
    $table->string('status')->default('draft')->change();
});
```

When you add a required column, set it everywhere rows are inserted in the same deploy, or give it a default.

## Find it in production

With `APP_DEBUG=false` the visitor gets a 500 page titled "Server Error", typically on the form or action that creates the record. Laravel reports the exception and writes it at error level to `storage/logs/laravel.log`. By default the logged message includes the insert SQL with every bound value, which means any personal data in that row reaches the log and any error tracker alike. `DB_MASK_BINDINGS=true` replaces the values with `?`; the column list stays, so the missing column still shows. Laravel reads it only through the `mask_bindings_in_exception_messages` key of the connection, so if your `config/database.php` connection has no such key, add `'mask_bindings_in_exception_messages' => env('DB_MASK_BINDINGS', false),` to it. Ranetrace's [error monitoring](/features/error-monitoring) records each one with its stack trace and the request it happened on.

Reproduced on Laravel 13.45, PHP 8.5, MySQL 8.0.27, 5 December 2026.

Read more: https://laravel.com/docs/migrations

## Related

### Terms

- [Eloquent ORM in Laravel](https://ranetrace.com/glossary/eloquent-orm-in-laravel.md)

### Other errors

- [Add \[x\] to fillable property to allow mass assignment](https://ranetrace.com/error-guides/laravel-mass-assignment-fillable.md)
- [SQLSTATE\[23000\]: Integrity constraint violation: 1452 Cannot add or update a child row](https://ranetrace.com/error-guides/laravel-sqlstate-1452-foreign-key-constraint.md)
- [SQLSTATE\[42S22\]: Column not found: 1054 Unknown column](https://ranetrace.com/error-guides/laravel-sqlstate-1054-unknown-column.md)

Read this guide in a browser: https://ranetrace.com/error-guides/laravel-sqlstate-1364-field-no-default
