“未初始化常量 MongoMapper::Base”执行 rake mongo:mongrate 时出错

发布于 2024-10-15 04:53:47 字数 1018 浏览 3 评论 0原文

我在“rake mongo:mongrate”尝试期间遇到以下错误:

$ rake mongo:mongrate --trace
(in /home/mei/Jobfully)
** Invoke mongo:mongrate (first_time)
** Invoke environment (first_time)
** Execute environment

** Execute mongo:mongrate
==  AddPricingPlans: migrating ================================================
-- add_column(:users, :plan_id, :string)
rake aborted!
uninitialized constant MongoMapper::Base
/home/mei/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `rescue in load_missing_constant'

我的 Gemfile 中有以下内容 -

gem 'rake', '~>0.8'
gem 'mongo',        '= 1.0.7'  # must be same version as bson/bson_ext
gem 'bson',         '= 1.0.4'  # must be same version as bson_ext/mongo
gem 'bson_ext',     '= 1.0.4'  # must be same version as bson/mongo
gem 'mongo_mapper', '~> 0.8.2'

我还在 Rakefile 中添加了以下行 -

import 'vendor/plugins/mongrations/lib/tasks/mongo.rake'

关于如何解决此问题的任何想法?谢谢。

I got the following error during my "rake mongo:mongrate" attempt:

$ rake mongo:mongrate --trace
(in /home/mei/Jobfully)
** Invoke mongo:mongrate (first_time)
** Invoke environment (first_time)
** Execute environment

** Execute mongo:mongrate
==  AddPricingPlans: migrating ================================================
-- add_column(:users, :plan_id, :string)
rake aborted!
uninitialized constant MongoMapper::Base
/home/mei/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `rescue in load_missing_constant'

I have the following in my Gemfile -

gem 'rake', '~>0.8'
gem 'mongo',        '= 1.0.7'  # must be same version as bson/bson_ext
gem 'bson',         '= 1.0.4'  # must be same version as bson_ext/mongo
gem 'bson_ext',     '= 1.0.4'  # must be same version as bson/mongo
gem 'mongo_mapper', '~> 0.8.2'

I also added the following line in Rakefile -

import 'vendor/plugins/mongrations/lib/tasks/mongo.rake'

Any ideas on how I can fix this problem? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2024-10-22 04:53:47

MongoMapper::Base 在去年的某个时候被弃用(它甚至不再存在!)。您现在需要 lib/mongo_mapper/mongrations.rb 中的 MongoMapper.connectiondef connection 而不是 MongoMapper::Base.connection< /代码>。

我不确定它什么时候坏掉的,但是做出这样的改变对我来说已经解决了问题。

如果你想对其进行猴子补丁,你可以使用:

module MongoMapper
  class Base
    def self.connection
      MongoMapper.connection
    end
  end
end

MongoMapper::Base was deprecated sometime in the last year (it no longer even exists!). You now want MongoMapper.connection in lib/mongo_mapper/mongrations.rb, def connection rather than MongoMapper::Base.connection.

I'm not sure when it broke, but making that change has fixed mongrations for me.

If you want to monkeypatch it, you could use:

module MongoMapper
  class Base
    def self.connection
      MongoMapper.connection
    end
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文