Why is my rails db:migrate not working?

jose tanaka picture jose tanaka · Jun 7, 2017 · Viewed 13.3k times · Source

I typed in rails db:migrate and received the following error. I googled and someone said something like changing the Migration version from [4.2] to [5.1] but it still has not worked.

rails db:migrate rails aborted! StandardError: An error has occurred, this and all later migrations canceled:

Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

class CreateCkeditorAssets < ActiveRecord::Migration[4.2]

Answer

Tachyons picture Tachyons · Oct 25, 2017

Aditya already wrote the answer, Changing all migrations by hand is a hectic task, So I wrote a one liner script to do that

In linux (Gnu sed)

grep -rl "ActiveRecord::Migration$" db | xargs sed -i 's/ActiveRecord::Migration/ActiveRecord::Migration[4.2]/g'

In Mac (BSD sed)

grep -rl "ActiveRecord::Migration$" db | xargs sed -i "" "s/ActiveRecord::Migration/ActiveRecord::Migration[4.2]/g"

Note, you can replace 4.2 with the rails from which you are upgrading to 5.1