mysql - Migration error: 1005 making more than one foreign keys in laravel 5.4 -


i getting error laravel 5.4 sql trying make many foreign key in 1 table product. please me. why getting error? looking , searching other codes structure of making more 1 foreign key migration code.

    [illuminate\database\queryexception]   sqlstate[hy000]: general error: 1005 can't create table `store_db`.`#sql-ca4_1f1` (errno: 150 "foreign key constrai   nt incorrectly formed") (sql: alter table `products` add constraint `products_product_img_id_foreign` foreign ke   y (`product_img_id`) references `product_images` (`product_img_id`) on delete cascade) 

here migration code: migration code products table:

public function up() {     schema::create('products', function (blueprint $table) {         $table->increments('product_id')->unsigned();         $table->integer('category_id')->unsigned();         $table->integer('product_img_id')->unsigned();         $table->string('feature_img');                     $table->string('product_name');         $table->text('description');         $table->double('price',15,2);         $table->integer('quantity');         $table->timestamps();          $table->foreign('category_id')         ->references('category_id')->on('categories')         ->ondelete('cascade');          $table->foreign('product_img_id')         ->references('product_img_id')->on('product_images')         ->ondelete('cascade');     }); }  /**  * reverse migrations.  *  * @return void  */ public function down() {     schema::drop('categories');     // schema::drop('product_images');     schema::drop('products');       } 

migration code product_images table:

public function up()     {         schema::create('product_images', function (blueprint $table) {             $table->increments('product_img_id')->unsigned();             $table->string('product_img');                     });     }      /**      * reverse migrations.      *      * @return void      */     public function down()     {         schema::dropifexists('product_images');     } 

migration code categories table:

public function up()     {         schema::create('categories', function (blueprint $table) {             $table->increments('category_id')->unsigned();             $table->string('name');             $table->text('description');             $table->string('category_img');                         $table->timestamps();         });     }      /**      * reverse migrations.      *      * @return void      */     public function down()     {         schema::dropifexists('categories');     } 

any suggestions?


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -