LoginSignup
1

More than 5 years have passed since last update.

[エラー] Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails

Posted at

Railsでマイグレーション。
外部キーを設定しようとしてタイトルのエラー発生。

原因

参照元のデータが削除されているが、参照先には残っているなど、不整合な外部キーが存在

対処

不整合な外部キーをもつデータを削除すればいいみたい。

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