简体   繁体   中英

Laravel 6 - MariaDB 10.1: Illuminate\Database\QueryException : SQLSTATE[HY000] migration error

I have custom migration:

Code:

// Groups migration
Schema::create('groups', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('name');
    $table->boolean('status')->default(false);
    $table->timestamps();
});

// Clients migration
Schema::create('clients', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('fullname');
    $table->integer('phone');
    $table->date('birthday')->nullable();
    $table->boolean('can_get_congratulations')->default(false);
    $table->unsignedInteger('group_id')->default(null);
    $table->foreign('group_id')
          ->references('id')
          ->on('groups')
          ->onDelete('cascade');
    $table->boolean('status')->default(true);
    $table->timestamps();
});

When I run this migration file then get error message:

Illuminate\\Database\\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table taxisms . #sql-1cc0_65c (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table clients add constraint clients_group_id_foreign foreign key ( group_id ) references groups ( id ) on delete cascade)

在此处输入图片说明

Where I have an error in my migration code?

The column needs to match on both sides. Since groups.id is an unsigned big integer, group_id will need to be as well. Change

$table->unsignedInteger('group_id') 

to

$table->unsignedBigInteger('group_id')

See this Blog Site. I hope that this article helpful to you. Also, know another topic on this site.

https://eduproblem.xyz/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM