以下のコマンドを打つと、mysqlのエラーが出てしまいます。
どこのファイルを確認し、どのように対応すればよいのか調べても未だわかりません。
$bundle exec rails db:drop $bundle exec rails db:create $bundle exec rails db:migrate $bundle exec rails db:seed_fu ActiveRecord::InvalidForeignKey: Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails (`ticket_development`.`organizers`, CONSTRAINT `fk_rails_0a7288d935` FOREIGN KEY (`stadium_id`) REFERENCES `stadia` (`id`)): INSERT INTO `organizers` (`id`, `name`, `category_id`, `league_id`, `created_at`, `updated_at`, `stadium_id`) VALUES (1, '読売ジャイアンツ', 1, 1, '2018-03-30 07:24:44', '2018-03-30 07:24:44', 1) (eval):1:in `block (2 levels) in run_file' bin/rails:4:in `require' bin/rails:4:in `<main>' Caused by: Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails (`ticket_development`.`organizers`, CONSTRAINT `fk_rails_0a7288d935` FOREIGN KEY (`stadium_id`) REFERENCES `stadia` (`id`)) (eval):1:in `block (2 levels) in run_file' bin/rails:4:in `require' bin/rails:4:in `<main>' Tasks: TOP => db:seed_fu (See full trace by running task with --trace)
以下の2つの方法を試しましたが、それでも解決されませんでした。
①外部キーの取り外しと再設定
mysql> alter table organizers drop foreign key fk_rails_0a7288d935; Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table organizers add constraint fk_rails_0a7288d935 foreign key (stadium_id) references stadia(id) on delete cascade on update cascade; Query OK, 0 rows affected (0.11 sec) Records: 0 Duplicates: 0 Warnings: 0
②ローカルブランチを削除し、他の人が成功したものをリモートにpushしてもらい、再度ローカルブランチを作成しpullしてくる。
どこに原因があるかつかめない状態です、
ご教授よろしくお願いいたします。
あなたの回答
tips
プレビュー