如何解决无法创建表`clothing`.`clothes`错误号:150“外键约束格式不正确””Laravel 7
无法创建表clothing
。clothes
(错误号: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');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。