マイグレーションファイルを誤って作成してしまい修正を試みたところ、
rails db:rollback時に出てしまうエラーが解決できず質問をさせて頂きたいです。
<作業工程>
①notificationモデル、マイグレーションファイルを作成→rails db:migrate
②マイグレーションファイルにつけた add_indexにミス発覚(カラム名をpost_idからitem_idへ変更したい)
③rollback後にadd_item_to_notificationsマイグレーションファイルを作成し記入
html
1class AddItemToNotifications < ActiveRecord::Migration[6.1] 2def up 3 remove_index :notifications, :post_id 4 add_index :notifications, :item_id 5 end 6 7 def down 8 remove_index :notifications, :post_id 9 add_index :notifications, :item_id 10 end
→rails db:migrate
④スキームに修正反映される
⑤確認の為、rails db:rollbackを試したところエラーが出てしまいました。
<rails db:rollback時のエラー文>
html
1Running via Spring preloader in process 29625 2== 20220705030923 AddItemToNotifications: reverting =========================== 3-- remove_index(:notifications, :post_id) 4rake aborted! 5StandardError: An error has occurred, this and all later migrations canceled: 6 7No indexes found on notifications with the options provided. 8/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-6.1.5.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1411:in `index_name_for_remove'
<schemaファイル変更反映箇所>
t.index ["post_id"]→t.index ["item_id"]
html
1 create_table "notifications", force: :cascade do |t| 2 t.integer "visitor_id", null: false 3 t.integer "visited_id", null: false 4 t.integer "item_id" 5 t.integer "comment_id" 6 t.string "action", default: "", null: false 7 t.boolean "checked", default: false, null: false 8 t.datetime "created_at", precision: 6, null: false 9 t.datetime "updated_at", precision: 6, null: false 10 t.index ["comment_id"], name: "index_notifications_on_comment_id" 11 t.index ["item_id"], name: "index_notifications_on_item_id" 12 t.index ["visited_id"], name: "index_notifications_on_visited_id" 13 t.index ["visitor_id"], name: "index_notifications_on_visitor_id" 14 end 15
<マイグレーションファイルの状態>
html
1database: db/development.sqlite3 2 3 Status Migration ID Migration Name 4-------------------------------------------------- 5up 20220705022642 Create notifications 6up 20220705030923 Add item to notifications
remove_index(:notifications, :post_id)でエラーが出ているようなのですが原因や解決方法を調べるも分からず質問をさせて頂きたいです。
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。