お世話になっております。
当方Laravel5.5にてWebSiteを構築しております、
環境はmac OS Mojave10.14.2
ブラウザはGoogle Chrome バージョン: 71.0.3578.98になります。
データベースはphpMyAdminです。
migrationを行うと、下記エラーが発生します。
親のキーはincrementsで、
子はunsignedIntegerでuniqueキーとしています。
何が原因でしょうか?
エラーメッセージ
php
1SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
外部キーの親と子
親
php
1class XXXX extends Migration 2{ 3 /** 4 * Run the migrations. 5 * 6 * @return void 7 */ 8 public function up() 9 { 10 Schema::create('m_aaa_category', function (Blueprint $table) { 11 $table->increments('aaa_category_id'); 12 $table->string('aaa_category_name',64); 13 $table->boolean('valid_flg')->comment = '0:無効 1:有効'; 14 $table->timestamps(); 15 }); 16 } 17 18 /** 19 * Reverse the migrations. 20 * 21 * @return void 22 */ 23 public function down() 24 { 25 Schema::dropIfExists('m_aaa_category'); 26 } 27} 28
子
php
1class XXXX extends Migration 2{ 3 /** 4 * Run the migrations. 5 * 6 * @return void 7 */ 8 public function up() 9 { 10 Schema::create('m_bbb_type', function (Blueprint $table) { 11 $table->increments('bbb_type_id'); 12 $table->string('bbb_type_name',64); 13 $table->unsignedInteger('aaa_category_id')->unique(); 14 $table->boolean('valid_flg')->comment = '0:無効 1:有効'; 15 $table->timestamps(); 16 17 $table->foreign('aaa_category_id') 18 ->references('aaa_category_id') 19 ->on('m_aaa_category') 20 ->onDelete('cascade') 21 ->onUpdate('cascade'); 22 }); 23 } 24 25 /** 26 * Reverse the migrations. 27 * 28 * @return void 29 */ 30 public function down() 31 { 32 Schema::dropIfExists('m_bbb_type'); 33 } 34} 35
宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。