NoMethodError:未定义的方法`needs_migration?' 对于ActiveRecord :: Migrator:Class

liq*_*ord 3 activerecord ruby-on-rails nomethoderror

我收到以下错误消息,不知道如何解决它.有人可以帮忙吗?

NoMethodError:未定义的方法`needs_migration?' 对于ActiveRecord :: Migrator:Class

这是config.ru代码:

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
Run Code Online (Sandbox Code Playgroud)

Rav*_*iya 7

将您的代码更改为

if ActiveRecord::Base.connection.migration_context.needs_migration?
  raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
end
Run Code Online (Sandbox Code Playgroud)