Why are my db: migrate rails not working?

I typed rails db:migrate and got the following error. I googled and someone said something like changing the migration version from [4.2] to [5.1], but it still didn't work.

rails db: migrate rails aborted! StandardError: an error occurred, this and all subsequent migrations are canceled:

Directly inheriting from ActiveRecord :: Migration is not supported. Please indicate the release of Rails for which the migration was performed:

class CreateCkeditorAssets <ActiveRecord :: Migration [4,2]

+8
ruby-on-rails
source share
2 answers

Rails 5 has changed the way you create migration. You will need to specify the Rails release starting with Rails 5, like this (if you are using Rails 5.1):

 class CreateCkeditorAssets < ActiveRecord::Migration[5.1] 

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

 rails g model Test name:string 
+13
source share

Aditya already wrote the answer. Changing all hyphenation manually is a difficult task. So I wrote one liner script to do this

On linux (Gnu sed)

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

On 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 rails, of which yiu is upgraded to 5.1

+8
source share

All Articles