前提・実現したいこと
ファイルを編集前にdb;migrate
してしましました。
ファイルを編集したので
up 20210410003113 Add post id comments
db:migrateをやり直したいです。。
Status Migration ID Migration Name -------------------------------------------------- up 20210409101436 Create posts up 20210410003113 Add post id comments up 20210410003607 Create comments
発生している問題・エラーメッセージ
rails db:rollback STEP=2 == 20210410003607 CreateComments: reverting =================================== -- drop_table(:comments) -> 0.0024s == 20210410003607 CreateComments: reverted (0.0042s) ========================== == 20210410003113 AddPostIdComments: reverting ================================ rails aborted! StandardError: An error has occurred, this and all later migrations canceled: undefined method `add_reference ' for #<AddPostIdComments:0x00007fc8aa183088> /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/db/migrate/20210410003113_add_post_id_comments.rb:3:in `change' /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/bin/rails:9:in `<top (required)>' /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Caused by: NoMethodError: undefined method `add_reference ' for #<AddPostIdComments:0x00007fc8aa183088> /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/db/migrate/20210410003113_add_post_id_comments.rb:3:in `change' /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/bin/rails:9:in `<top (required)>' /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Tasks: TOP => db:rollback (See full trace by running task with --trace) mark_naito@marknoMacBook-Air CRUD_app_3 % rails db:status rails aborted! Don't know how to build task 'db:status' (See the list of available tasks with `rails --tasks`) Did you mean? db:setup /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/bin/rails:9:in `<top (required)>' /Users/mark_naito/workspace/runteq/event/Basic_ability_task/CRUD_app_3/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' (See full trace by running task with --trace)
該当のソースコード
class AddPostIdComments < ActiveRecord::Migration[5.2] def change add_reference :comments, :post, null: false end end
試したこと
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/04/10 05:21