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

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

我收到以下错误消息,不确定如何解决。有人可以帮忙吗?

NoMethodError: undefined method `needs_migration?' for 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

将您的代码更改为

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