Solvedrolify Directly inheriting from ActiveRecord::Migration is not supported

Rails: 5.1.0.beta1
Ruby: 2.4.0
Rolify: 5.1.0

This generated migration fails on this version of rails

  class RolifyCreateRoles < ActiveRecord::Migration
    def change
      ...
    end
  end
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 RolifyCreateRoles < ActiveRecord::Migration[4.2]
/Users/brandoncordell/Code/dsk_group/db/migrate/20170307143104_rolify_create_roles.rb:1:in `<top (required)>'
/Users/brandoncordell/Code/dsk_group/bin/rails:9:in `require'
/Users/brandoncordell/Code/dsk_group/bin/rails:9:in `<top (required)>'
/Users/brandoncordell/Code/dsk_group/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

  class RolifyCreateRoles < ActiveRecord::Migration[4.2]
/Users/brandoncordell/Code/dsk_group/db/migrate/20170307143104_rolify_create_roles.rb:1:in `<top (required)>'
/Users/brandoncordell/Code/dsk_group/bin/rails:9:in `require'
/Users/brandoncordell/Code/dsk_group/bin/rails:9:in `<top (required)>'
/Users/brandoncordell/Code/dsk_group/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Solution: I change class RolifyCreateRoles < ActiveRecord::Migration to class RolifyCreateRoles < ActiveRecord::Migration[5.0]

25 Answers

✔️Accepted Answer

@jermaine Thanks. To prevent any which would already have a version tag, I changed your one-liner to the following:

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

Note the $.

Other Answers:

@redtachyons When running this on OSX I get the following error:

...extra characters at the end of d command

To get around this I had to add an empty string to sed.

This worked for me.
grep -rl "ActiveRecord::Migration" db | xargs sed -i "" "s/ActiveRecord::Migration/ActiveRecord::Migration[5.1]/g"

Thanks for the tip, Here is one liner to do that in linux

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

Thank u for the solution @brandoncordell

Related Issues:

38
rolify Directly inheriting from ActiveRecord::Migration is not supported
@jermaine Thanks To prevent any which would already have a version tag I changed your one-liner to t...