问题描述
无法创建表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');