LoginSignup
0
0

More than 3 years have passed since last update.

Laravel 6.0, MySQL8.0 にて、SQLSTATE[HY000]: General error: 1822 Failed to add the foreign key constraint

Posted at
PDOException::("SQLSTATE[HY000]: General error: 1822 Failed to add the foreign key constraint. Missing index for constraint 'advisors_user_id_foreign' in the referenced table 'users'")

Laravelでマイグレーション時に外部キーをセットしようとしたが、idがPKじゃ無くなっていたことにより上記エラーが出た

$table->primary('id')を加えてあげることで解決

0
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
0
0