rolify: 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]

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 280
  • Comments: 24 (1 by maintainers)

Commits related to this issue

Most upvoted comments

@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 $.

@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’

I just downgraded my rails to v5.0.5 and was able to run a migration without issues. I restored my app to use v5.1.3 and it started up.

Thank u for the solution @brandoncordell

@jermaine seems like that is a slight behavior change between Gnu sed and Bsd sed

Funny, but on 5.1.3 you still need add version to migration file.

Thank you @brandoncordell! I have been scratching my head all morning trying to figure that out!

*Rails 5.1.4.

Thanks @brandoncordell. This fixed it for me.

thanks

@brandoncordell – Thanks