Home > Net >  in laravel SQLSTATE[HY000]: General eror: -625 validation error for column id, value "*** null
in laravel SQLSTATE[HY000]: General eror: -625 validation error for column id, value "*** null

Time:01-02

I have the following error when registering in laravel.

Laravel version 8
Database: Firebird \

I use the regular form. When registering the form, the following error appears:

SQLSTATE[HY000]: General error: -625 validation error for column id, value "*** null ***" (SQL: insert into "users" ("name", "email", "password", "updated_at", "created_at") values (Pavel, [email protected] , $2y$10$hqno7.foR2zNuSZvaONfEOjEuXJRdVo2PxXhs9q6jgi.hduuf1kjg, 2023-01-01 11:03:22, 2023-01-01 11:03:22))

Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});

CodePudding user response:

The error seems to be you aren't providing an ID, the id is null. An ID in an Firebird table shouldn't be autoincrement by default.

I suggest you to use UUID. I provide you the migration modified and what you should do in your model User:

Schema::create('users', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});

In your model User, you should add this changes:

protected $primaryKey='id';
public $incrementing=false;
protected $keyType='string';

protected static function boot()
{
    parent::boot();
    static::creating(function ($model) {
        if (empty($model->{$model->getKeyName()})) {
            $model->{$model->getKeyName()} = Str::uuid()->toString();
        }
    });
}

You should be able to use it now without any problem

  • Related