問題
migration実行時に ```SQLSTATE[HY000]: General error: 1005 Can't create table 'hoge.#sql-935_2e' (errno: 150) (SQL: alter table `m_answer_options` add constraint `m_answer_options_question_id_foreign` foreign key (`question_id`) references `m_questions` (`id`))``` のエラーが出た。原因
外部キーを設定するときに、参照先のテーブルがBIGINT、参照元がINTになっている。(例)
【参照先のマイグレーションファイル】
yyyy_mm_dd_061000_create_m_questions_table.php
$table->BigIncrements('id');
【参照元のマイグレーションファイル】
yyyy_mm_dd_061032_create_m_answer_options_table.php
$table->foreign('question_id')->references('id')->on('m_questions');
対応方法
参照先テーブルを作成するマイグレーションファイル(yyyy_mm_dd_061000_create_m_questions_table.php)のbigIncrementsをincrementsに変更した。(例)
【修正前】
$table->BigIncrements('id');
【修正後】
$table->increments('id');