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]
When you run db:migrate, rails will check a special table in the database which contains the timestamp of the last migration applied to the database. It will then apply all of the migrations with timestamps after that date and update the database table with the timestamp of the last migration.
rake db:migrate:status (Rails 3 to 5) or rails db:migrate:status (Rails 5) will accomplish this. See this commit. up means the migration has been run. down means the migration has not been run.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With