NoMethodError: undefined method `needs_migration?' for ActiveRecord::Migrator:Class
Asked Answered
O

1

4

I'm getting the below error message, not sure how to resolve it. Can anyone help please?

NoMethodError: undefined method `needs_migration?' for ActiveRecord::Migrator:Class

Here is the config.ru code:

require './config/environment'

if ActiveRecord::Migrator.needs_migration?
  raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
end

use Rack::MethodOverride

use UsersController
use ArtworkController
run ApplicationController
Ophthalmia answered 11/6, 2018 at 4:45 Comment(4)
Share your sample code as well.Turbine
which rails version are you using?Unlatch
Hi @Ravi mariya, I'm using Rails 5.1.4Ophthalmia
Ok, then i think this will not work in rails5Unlatch
U
14

change your code to

if ActiveRecord::Base.connection.migration_context.needs_migration?
  raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
end
Unlatch answered 12/6, 2018 at 5:59 Comment(2)
Awesome! Thanks Ravi! Much appreciated :)Ophthalmia
What if there is more than 1 connection in ActiveRecord?Navarra

© 2022 - 2024 — McMap. All rights reserved.