我有自定义迁移:代码:// Groups migrationSchema::create('groups', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->boolean('status')->default(false); $table->timestamps();});// Clients migrationSchema::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();});当我运行此迁移文件时,会收到错误消息:Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table taxisms。#sql-1cc0_65c(errno: 150 "Foreign key constraint is wrongly forms") (SQL: alter table clientsadd constraint clients_group_id_foreignforeign key ( group_id) references groups( id) on delete cascade)我的迁移代码哪里有错误?
1 回答
守着一只汪
TA贡献1872条经验 获得超3个赞
该列需要在两侧匹配。由于groups.id
是无符号大整数,因此 group_id 也需要。改变
$table->unsignedInteger('group_id')
到
$table->unsignedBigInteger('group_id')
- 1 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消