1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SQLSTATE[HY000]: General error: 1005 Can't create table 'hoge.#sql-935_2e' (errno: 150) のエラーが出たときの対処法

1
Last updated at Posted at 2019-12-04

問題

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');

参考ページ

https://github.com/laravel/framework/issues/28793
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?