Laravel 6-MariaDB 10.1:Illuminate \ Database \ QueryException:SQLSTATE [HY000]迁移错误

时间:2019-11-27 18:53:51

标签: php mysql laravel mariadb

我有自定义迁移:

代码:

var x = document.getElementByClassName("section-background"); 
x.setAttribute("id", "vantajs");

当我运行此迁移文件时,出现错误消息:

  

Illuminate \ Database \ QueryException:SQLSTATE [HY000]:常规错误:   1005无法创建表// 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(); }); taxisms(错误号:150“ Foreign   键约束的格式不正确”)(SQL:alter table #sql-1cc0_65c add   约束clients外键(clients_group_id_foreign)   在删除级联上引用group_idgroups

enter image description here

我的迁移代码哪里有错误?

1 个答案:

答案 0 :(得分:1)

该列需要在两侧都匹配。由于groups.id是一个无符号的大整数,因此group_id也必须是。更改

$table->unsignedInteger('group_id') 

$table->unsignedBigInteger('group_id')