为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel 6 - MariaDB 10.1:Illuminate\Database\

Laravel 6 - MariaDB 10.1:Illuminate\Database\

PHP
Qyouu 2022-05-27 14:37:01
我有自定义迁移:代码:// 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')


查看完整回答
反对 回复 2022-05-27
  • 1 回答
  • 0 关注
  • 126 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信