Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KalimeroMK's avatar

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

Model is

resource class is

payload

Body
{
    "_token": "YJsQDxsa70uTrhpBFjcbvoeyVnQ9TWMIjq0I44FZ",
    "components": [
        {
            "snapshot": "{"data":{"record":null,"data":[{"name":null,"description":null,"categories":null,"image":[[],{"s":"arr"}]},{"s":"arr"}],"previousUrl":"http://localhost:86/admin/categories","mountedActions":[[],{"s":"arr"}],"mountedActionsArguments":[[],{"s":"arr"}],"mountedActionsData":[[],{"s":"arr"}],"defaultAction":null,"defaultActionArguments":null,"componentFileAttachments":[[],{"s":"arr"}],"mountedFormComponentActions":[[],{"s":"arr"}],"mountedFormComponentActionsArguments":[[],{"s":"arr"}],"mountedFormComponentActionsData":[[],{"s":"arr"}],"mountedFormComponentActionsComponents":[[],{"s":"arr"}],"mountedInfolistActions":[[],{"s":"arr"}],"mountedInfolistActionsData":[[],{"s":"arr"}],"mountedInfolistActionsComponent":null,"mountedInfolistActionsInfolist":null,"savedDataHash":null},"memo":{"id":"Fnm8X0BllrvoQtwQIIQX","name":"app.filament.resources.category-resource.pages.create-category","path":"admin/categories/create","method":"GET","children":[],"scripts":[],"assets":[],"errors":[],"locale":"en"},"checksum":"35849328f8618782d9610a53b642beb74426120204cde196a45b132e9de7aafa"}",
            "updates": {
                "data.name": "dsadas",
                "data.description": "<p>dsada</p>",
                "data.categories": 3
            },
            "calls": [
                {
                    "path": "",
                    "method": "create",
                    "params": []
                }
            ]
        }
    ]
}

don't understant what is the problem

0 likes
14 replies
Tray2's avatar

The problem is in the database, the name field is empty, and you most likely have that set as not null, which then generates the problem. Make sure the the name value is passed properly.

"name":null,
KalimeroMK's avatar

@Tray2 the problem is not in the database name how you can see in categoryresource is required so the name is present but not pass for saving in the load we have "data.name": "dsadas", "data.description": "dsada", "data.categories": 3 but why get null on save dont now

Tray2's avatar

@KalimeroMK Trust me, I work with databases every day and that error means that you are attempting to insert a null value in the name field, and since it doesn't have a default value, it throws that exact error. You need to make sure that you pass the name to the database.

KalimeroMK's avatar

@Tray2 I understand what you are talking but you dont understand me I pass category name

"data.name": "dsadas",
 "data.description": "<p>dsada</p>",
 "data.categories": 3

form the form but still tray to inser null value this is the problem if filed is requerd cenot be null if a enter name for the category whay it trai to insert null values this is my question and problem

KalimeroMK's avatar

@Tray2 thet is my question way it pass null value when i put nema for the category

Sinnbeck's avatar

Check your CreateCategory class (I assume you are getting the error when creating a new record?) to see if you perhaps have a method that intercepts with the creation of models. Perhaps you are returning an empty array

KalimeroMK's avatar

@Sinnbeck

<?php

namespace App\Filament\Resources\CategoryResource\Pages;

use App\Filament\Resources\CategoryResource;
use Filament\Resources\Pages\CreateRecord;

class CreateCategory extends CreateRecord
{
    protected static string $resource = CategoryResource::class;

    protected function getHeaderActions(): array
    {
        return [

        ];
    }
}

the class is empty how is created for start when create filament resource

Sinnbeck's avatar

Give the full error then. Is it even the categories table?

Sinnbeck's avatar

Also you didn't show the full model. Maybe there is a mutator?

KalimeroMK's avatar

@Sinnbeck

full model

KalimeroMK's avatar

@Snapey in my filament create class

<?php

namespace App\Filament\Resources\CategoryResource\Pages;

use App\Filament\Resources\CategoryResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Log;

class CreateCategory extends CreateRecord
{
    protected static string $resource = CategoryResource::class;

    protected function mutateFormDataBeforeCreate(array $data): array
    {
        Log::info('Final Data Sent to Database:', $data);
        return $data;
    }

    protected function afterCreate(): void
    {
        Log::info('Category Created Successfully:', ['id' => $this->record->id]);
    }
}

i add login and log shows

[2025-03-06 11:40:35] local.INFO: Final Data Sent to Database: {"name":"asdasd","description":"<p>dasdasd</p>","categories":77,"image":"01JNNM3RSJBX8EG41RDRTYVDZX.png"} 
[2025-03-06 11:40:35] local.ERROR: SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (Connection: mysql, SQL: insert into `categories` (`updated_at`, `created_at`) values (2025-03-06 11:40:35, 2025-03-06 11:40:35)) {"userId":3,"exception":"[object] (Illuminate\\Database\\QueryException(code: HY000): SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (Connection: mysql, SQL: insert into `categories` (`updated_at`, `created_at`) values (2025-03-06 11:40:35, 2025-03-06 11:40:35)) at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825)
[stacktrace]

Please or to participate in this conversation.