From 7a0c89e70bf4a4e4c88b670d45e019de4622d9f4 Mon Sep 17 00:00:00 2001 From: Ken Date: Thu, 7 Oct 2021 22:55:59 +0800 Subject: [PATCH] Fixed the SQLSTATE[HY000]: General error: 1005 (errno: 150 "Foreign key constraint is incorrectly formed") --- .../2019_06_20_085828_create_attribute_values_table.php | 2 +- .../migrations/2019_07_24_083500_create_products_table.php | 2 +- .../2019_07_24_083527_create_product_images_table.php | 2 +- .../2019_07_24_090328_create_product_attributes_table.php | 4 ++-- .../2019_07_24_090552_create_product_categories_table.php | 4 ++-- ..._092222_create_attribute_value_product_attribute_table.php | 4 ++-- .../2019_08_12_094451_alter_product_attributes_table.php | 2 +- database/migrations/2019_09_11_150147_create_orders_table.php | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/database/migrations/2019_06_20_085828_create_attribute_values_table.php b/database/migrations/2019_06_20_085828_create_attribute_values_table.php index 33c860c..e07b960 100644 --- a/database/migrations/2019_06_20_085828_create_attribute_values_table.php +++ b/database/migrations/2019_06_20_085828_create_attribute_values_table.php @@ -15,7 +15,7 @@ public function up() { Schema::create('attribute_values', function (Blueprint $table) { $table->bigIncrements('id'); - $table->unsignedInteger('attribute_id'); + $table->bigInteger('attribute_id')->unsigned(); $table->foreign('attribute_id')->references('id')->on('attributes'); $table->text('value'); $table->decimal('price', 2)->nullable(); diff --git a/database/migrations/2019_07_24_083500_create_products_table.php b/database/migrations/2019_07_24_083500_create_products_table.php index 3e47d29..fe31c2d 100644 --- a/database/migrations/2019_07_24_083500_create_products_table.php +++ b/database/migrations/2019_07_24_083500_create_products_table.php @@ -15,7 +15,7 @@ public function up() { Schema::create('products', function (Blueprint $table) { $table->bigIncrements('id'); - $table->unsignedInteger('brand_id')->index(); + $table->bigInteger('brand_id')->unsigned()->index(); $table->string('sku'); $table->string('name'); $table->string('slug'); diff --git a/database/migrations/2019_07_24_083527_create_product_images_table.php b/database/migrations/2019_07_24_083527_create_product_images_table.php index 8df9343..900b7fb 100644 --- a/database/migrations/2019_07_24_083527_create_product_images_table.php +++ b/database/migrations/2019_07_24_083527_create_product_images_table.php @@ -15,7 +15,7 @@ public function up() { Schema::create('product_images', function (Blueprint $table) { $table->bigIncrements('id'); - $table->unsignedInteger('product_id')->index(); + $table->bigInteger('product_id')->unsigned()->index(); $table->string('full')->nullable(); $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade'); diff --git a/database/migrations/2019_07_24_090328_create_product_attributes_table.php b/database/migrations/2019_07_24_090328_create_product_attributes_table.php index 9a4fc9c..4395951 100644 --- a/database/migrations/2019_07_24_090328_create_product_attributes_table.php +++ b/database/migrations/2019_07_24_090328_create_product_attributes_table.php @@ -14,10 +14,10 @@ class CreateProductAttributesTable extends Migration public function up() { Schema::create('product_attributes', function (Blueprint $table) { - $table->increments('id'); + $table->bigIncrements('id'); $table->integer('quantity'); $table->decimal('price')->nullable(); - $table->unsignedInteger('product_id'); + $table->bigInteger('product_id')->unsigned(); $table->foreign('product_id')->references('id')->on('products'); $table->timestamps(); }); diff --git a/database/migrations/2019_07_24_090552_create_product_categories_table.php b/database/migrations/2019_07_24_090552_create_product_categories_table.php index b90934b..5e5f02b 100644 --- a/database/migrations/2019_07_24_090552_create_product_categories_table.php +++ b/database/migrations/2019_07_24_090552_create_product_categories_table.php @@ -15,9 +15,9 @@ public function up() { Schema::create('product_categories', function (Blueprint $table) { $table->bigIncrements('id'); - $table->integer('category_id')->unsigned()->index(); + $table->bigInteger('category_id')->unsigned()->index(); $table->foreign('category_id')->references('id')->on('categories'); - $table->integer('product_id')->unsigned()->index(); + $table->bigInteger('product_id')->unsigned()->index(); $table->foreign('product_id')->references('id')->on('products'); }); } diff --git a/database/migrations/2019_07_24_092222_create_attribute_value_product_attribute_table.php b/database/migrations/2019_07_24_092222_create_attribute_value_product_attribute_table.php index 8646d1d..34a9c44 100644 --- a/database/migrations/2019_07_24_092222_create_attribute_value_product_attribute_table.php +++ b/database/migrations/2019_07_24_092222_create_attribute_value_product_attribute_table.php @@ -15,9 +15,9 @@ public function up() { Schema::create('attribute_value_product_attribute', function (Blueprint $table) { $table->bigIncrements('id'); - $table->unsignedInteger('attribute_value_id'); + $table->bigInteger('attribute_value_id')->unsigned(); $table->foreign('attribute_value_id')->references('id')->on('attribute_values'); - $table->unsignedInteger('product_attribute_id'); + $table->bigInteger('product_attribute_id')->unsigned(); $table->foreign('product_attribute_id')->references('id')->on('product_attributes'); }); } diff --git a/database/migrations/2019_08_12_094451_alter_product_attributes_table.php b/database/migrations/2019_08_12_094451_alter_product_attributes_table.php index 6ad38f8..78a6bcf 100644 --- a/database/migrations/2019_08_12_094451_alter_product_attributes_table.php +++ b/database/migrations/2019_08_12_094451_alter_product_attributes_table.php @@ -15,7 +15,7 @@ public function up() { Schema::table('product_attributes', function (Blueprint $table) { - $table->unsignedInteger('attribute_id')->after('id'); + $table->bigInteger('attribute_id')->unsigned()->after('id'); $table->foreign('attribute_id')->references('id')->on('attributes')->onDelete('cascade'); $table->string('value')->after('attribute_id'); diff --git a/database/migrations/2019_09_11_150147_create_orders_table.php b/database/migrations/2019_09_11_150147_create_orders_table.php index 616a295..8cf1032 100644 --- a/database/migrations/2019_09_11_150147_create_orders_table.php +++ b/database/migrations/2019_09_11_150147_create_orders_table.php @@ -16,7 +16,7 @@ public function up() Schema::create('orders', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('order_number')->unique(); - $table->unsignedInteger('user_id'); + $table->bigInteger('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users'); $table->enum('status', ['pending', 'processing', 'completed', 'decline'])->default('pending');