3

In trying to do the command $rails db:migrate, I receive the following error:

    $ rails db:migrate RAILS_ENV=test
    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:

How do I specify the release the migration was written for? What file is this in? Thanks!

NR 15
  • 77
  • 1
  • 11

1 Answers1

5

Rails prevent from inheriting from ActiveRecord::Migration that's because migration API can change between different versions.

To solve it provide the version that you need for all your migration files: ActiveRecord::Migration[version_number]

class MigrationClassName < ActiveRecord::Migration[5.2]
end
Mosaaleb
  • 1,028
  • 1
  • 9
  • 23
  • Hi thank you for this! I didn't receive a notification to this question. As I've said, I'm very new to this... where exactly do I add this line? What file? – NR 15 Jun 15 '20 at 20:18
  • Add it to all files inside `db/migrate`. Just add the version at the end of every `ActiveRecord::Migration`. Also, what Rails version you use? what is the value of executing `ActiveRecord::Migration.current_version` in Rails console? – Mosaaleb Jun 15 '20 at 20:24
  • Thank you! That helped and executed the command successfully! – NR 15 Jun 15 '20 at 20:32
  • Also, I'm using `ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]` – NR 15 Jun 15 '20 at 20:33