28
votes

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]

2
can you paste complete backtrace?Vrushali Pawar
Show your migration. Also what's your rails versionSergio Tulentsev

2 Answers

55
votes

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

38
votes

Rails 5 changed the way migrations are created. You'll have to specify the Rails release starting Rails 5 like this (assuming you're using Rails 5.1):

class CreateCkeditorAssets < ActiveRecord::Migration[5.1]

Alternately, you can try creating a test migration and see how your version of Rails generates a migration and then take it from there:

rails g model Test name:string