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 tableclients
add constraintclients_group_id_foreign
foreign key (group_id
) referencesgroups
(id
) on delete cascade)
Where I have an error in my migration code?
cascade
, notcasecade
– aynbercascade
but also get error. See to updated question – Andreas Huntergroups
migration as well? – aynbergroups.id
is an unsigned big integer,group_id
will need to be as well. Change$table->unsignedInteger('group_id')
to$table->unsignedBigInteger('group_id')
– aynber