27

I am trying to migrate a Rails 3 app. I installed Rails v 5.1.5 using RVM. When trying db:migrate, I get the following.

rake aborted! StandardError: An error has occurred, all later migrations canceled:

Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

class SorceryCore < ActiveRecord::Migration[4.2]

Here is the Class Definition for Sorcerycore:

class SorceryCore < <%= migration_class_name %>        


  def change
    create_table :<%= model_class_name.tableize %> do |t|
      t.string :email,            :null => false
      t.string :crypted_password
      t.string :salt

      t.timestamps                :null => false
    end

    add_index :<%= model_class_name.tableize %>, :email, unique: true
  end
end
uberdave
  • 432
  • 1
  • 5
  • 14

3 Answers3

64

You have to specify the version in brackets like it says. Have you added any migrations since upgrading?

Example change from:

class SorceryCore < ActiveRecord::Migration

to

class SorceryCore < ActiveRecord::Migration[5.1]

You can add the version to all migrations by running this from your Rails root directory:

grep -rl ActiveRecord::Migration$ db | xargs sed -i "" "s/ActiveRecord::Migration/ActiveRecord::Migration[5.1]/g"
Bret Weinraub
  • 1,943
  • 15
  • 21
Trinculo
  • 1,950
  • 1
  • 17
  • 22
  • 1
    The class is defined in SorceryCore like so. class SorceryCore < <%= migration_class_name %> So, how would I add ActiveRecord::Migration[5.1]? And from where in the directory structure should I run your grep command? – uberdave Feb 15 '18 at 21:01
  • @ubiquitousDave - Ahh, I see. I thought that was an example from your code. Are you on the latest version of the `sorcery` gem? It looks like they define `migration_class_name` from the `Rails::VERSION::MAJOR` variable. – Trinculo Feb 15 '18 at 21:16
  • https://github.com/Sorcery/sorcery/blob/4e3fcdb8df16912424281322ce9f2862937846fc/lib/generators/sorcery/install_generator.rb is the source for that. I believe if you are on that latest version of sorcery - `gem update sorcery`...assuming your `Gemfile` is not locked to an older version, it will work. – Trinculo Feb 15 '18 at 21:18
  • Ok, I see that I need to work on the individual migrations. That did it! – uberdave Feb 15 '18 at 21:22
  • Any thoughts on how to handle this if the migrations are part of a gem we don't own/manage. – baash05 Dec 31 '21 at 00:00
  • If there isn't a newer version of the gem available, and you are trying to use it in a newer version of Rails, you might have to fork the repository, fix the migrations, push it up, and use your forked version of the repository. You might have to update some other dependencies as well. – Trinculo Jan 09 '22 at 14:29
  • 1
    Slightly changed code worked for Redmine plugins `grep -rl ActiveRecord::Migration$ db | xargs sed -i 's/ActiveRecord::Migration/ActiveRecord::Migration[5.1]/g'` – Aleksandar Pavić May 18 '22 at 08:32
2

In my case is that I was using and out-dated version of data_migrate:

bundle update data_migrate
# Using data_migrate 6.3.0 (was 5.3.2)
fguillen
  • 36,125
  • 23
  • 149
  • 210
2

Add your migration version at last Like

class SorceryCore < ActiveRecord::Migration[5.1]

so here [5.1] is your version so add version

if you don't know the version please check your previous migration, may you find there...

CHAVDA MEET
  • 777
  • 8
  • 14