我创建了三个表:产品、类别和子类别。为了在它们之间创建关系,我使用了外键。我该如何解决?
sub_categories - 表
Schema::create('sub_categories', function (Blueprint $table) {
$table->string('id');
$table->string('cat_id');
$table->timestamps();
$table->string('cat_id')
->references('id')
->on('categories')
->onDelete('cascade');
});
类别 - 表
Schema::create('categories', function (Blueprint $table) {
$table->string('id');
$table->string('cat_name');
$table->string('cat_image_path')->nullable();
$table->string('cat_description')->nullable();
$table->timestamps();
});
产品 - 桌子
Schema::create('products', function (Blueprint $table) {
$table->string('id');
$table->string('prod_name');
$table->string('prod_brand')->nullable();
$table->string('cat_id');
$table->string('prod_description')->nullable();
$table->string('prod_item_code')->nullable();
$table->string('prod_modal')->nullable();
$table->string('prod_size')->nullable();
$table->string('prod_weight')->nullable();
$table->string('prod_height')->nullable();
$table->string('prod_manufacturer')->nullable();
$table->float('prod_price')->nullable();
$table->float('prod_discount')->nullable();
$table->float('prod_quantity')->nullable();
$table->string('prod_image_path')->nullable();
$table->timestamps();
$table->foreign('cat_id')
->references('id')
->on('categories')
->onDelete('cascade');
});
有人可以帮忙解决这个问题吗?
宝慕林4294392
慕容708150