php - 无法创建表`clothing`.`clothes`(errno:150“外键约束形成错误”)“)Laravel 7
问题描述
无法创建表clothing
。clothes
(errno: 150 "外键约束格式不正确")") Laravel 7
不能断言外键。
乐队
Schema::create('bands', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('band_origin');
$table->text('band_details');
$table->timestamps();
$table->softDeletes();
});
类别
Schema::create('category', function (Blueprint $table) {
$table->id();
$table->string('category_name');
$table->string('category_description');
$table->timestamps();
$table->softDeletes();
**gender**
Schema::create('gender', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->timestamps();
$table->softDeletes();
**colors**
Schema::create('colors', function (Blueprint $table) {
$table->id('idColor');
$table->String('color_name');
$table->String('color_description')->nullable();
$table->timestamps();
$table->softDeletes();
});
**ERROR HERE TABLE CLOTHES WHERE I WANT to ACQUIRE those field in this table**
Schema::create('clothes', function (Blueprint $table) {
$table->id('clothesID'); //PK
$table->bigInteger('bandID_fk')->unsigned();
$table->bigInteger('categoryID_fk')->unsigned();
$table->bigInteger('genderID_fk')->unsigned();
$table->bigInteger('colorID_fk')->unsigned();
$table->tinyInteger('onStock');
$table->integer('price');
$table->integer('discount')->default(0);
$table->string('description')->nullable();
$table->integer('shoeSize')->nullable();
$table->integer('stock');
$table->string('photo1');
$table->string('photo2')->nullable();
$table->string('photo3')->nullable();
$table->timestamps();
$table->softDeletes();
// ERROR
$table->foreign('bandID_fk')->references('id')->on('bands');
$table->foreign('categoryID_fk')->references('id')->on('category');
$table->foreign('genderID_fk')->references('id')->on('gender');
$table->foreign('colorID_fk')->references('idColor')->on('users');
});
}
解决方案
这是正确的答案 谢谢!
Schema::create('clothes', function
(Blueprint $table) {
$table->id('clothesID'); //PK
$table->bigInteger('bandID_fk')->unsigned();
$table->bigInteger('categoryID_fk')->unsigned();
$table->bigInteger('genderID_fk')->unsigned();
$table->bigInteger('colorID_fk')->unsigned();
$table->tinyInteger('onStock');
$table->integer('price');
$table->integer('discount')->default(0);
$table->string('description')->nullable();
$table->integer('shoeSize')->nullable();
$table->integer('stock');
$table->string('photo1');
$table->string('photo2')->nullable();
$table->string('photo3')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('bandID_fk')->references('id')->on('bands');
$table->foreign('categoryID_fk')->references('id')->on('category');
$table->foreign('genderID_fk')->references('id')->on('gender');
$table->foreign('colorID_fk')->references('idColor')->on('colors');
推荐阅读
- java - Camel Aws 使用 acl public 移动文件
- javascript - 为什么 setState 回调会抛出错误:“来自 useState() 和 useReducer() Hooks 的状态更新不支持第二个回调参数...”
- vue.js - router-link 无法跳转到页面
- python - Django rest 框架反转序列化器
- php - 错误列计数不计算第 1 行的计数
- apache-spark - Openshift 上的 Spark 历史服务器
- javascript - 如何在 MongoDB-Memory-Server 中测试静态类方法?
- swift - 当应用程序在后台运行或关闭时,Firebase 消息无法在 IOS 上运行
- arrays - 使用 *ngFor 在 Angular html 页面中显示数组数据
- c# - 发送 HttpRequestMessage 集合内部服务器端