[英]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
.Illuminate \\ Database \\ QueryException:SQLSTATE [HY000]:常规错误:1005无法创建表
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)#sql-1cc0_65c
(错误号:150“外键约束#sql-1cc0_65c
不正确”)(SQL:更改表clients
添加约束,clients_group_id_foreign
外键(group_id
)引用删除级联上的groups
(id
))
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. 由于
groups.id
是一个无符号的大整数,因此group_id也必须是。 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.
另外,请知道此站点上的另一个主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.