![](/img/trans.png)
[英]Docker Laravel migration error Illuminate\Database\QueryException SQLSTATE[HY000]
[英]Laravel 6 - MariaDB 10.1: Illuminate\Database\QueryException : SQLSTATE[HY000] migration error
我有自定義遷移:
碼:
// 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();
});
當我運行此遷移文件時,出現錯誤消息:
Illuminate \\ Database \\ QueryException:SQLSTATE [HY000]:常規錯誤:1005無法創建表
taxisms
。#sql-1cc0_65c
(錯誤號:150“外鍵約束#sql-1cc0_65c
不正確”)(SQL:更改表clients
添加約束,clients_group_id_foreign
外鍵(group_id
)引用刪除級聯上的groups
(id
))
遷移代碼中哪里有錯誤?
該列需要在兩側都匹配。 由於groups.id
是一個無符號的大整數,因此group_id也必須是。 更改
$table->unsignedInteger('group_id')
至
$table->unsignedBigInteger('group_id')
請參閱此博客網站。 希望本文對您有所幫助。 另外,請知道此站點上的另一個主題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.