【问题标题】:Cannot load mysql2 gem无法加载 mysql2 gem
【发布时间】:2016-05-18 14:52:47
【问题描述】:

我已经看过somedifferentanswers,但这些都没有帮助我......

这就是诀窍:我必须在接触 Gemfile 的情况下解决这个问题。我目前正在创建我的工作环境,以便它与生产服务器匹配,因此,我根本无法修改 rails 的代码。

我的操作系统:OSX 10.11

红宝石:红宝石 2.0.0p643

导轨:4.0.0

gem 是 gem 'mysql2' 的 Gemfile。执行bundle install 时没有错误,但是当我尝试rake db:migrate --trace 时,输出如下:

rake aborted!
There was an error while trying to load the gem 'mysql2'.
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
/Users/redar/redar/config/application.rb:7:in `<top (required)>'
/Users/redar/redar/Rakefile:4:in `require'
/Users/redar/redar/Rakefile:4:in `<top (required)>'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/rake:23:in `load'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/rake:23:in `<main>'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'

我不知道如何解释。 Rakefile 有问题吗?

另外,这是output from the mkmf.log


编辑:这是我的 Rakefile 的内容,位于 myapp/folder

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

MyApp::Application.load_tasks

【问题讨论】:

  • 我假设您的系统中安装了 mysql,对吗? (brew install mysql)
  • 看看这个问题:github.com/rails/rails/issues/21544,你可能想在你的 gemfile 中尝试 "gem 'mysql2', '~> 0.3.18'"
  • 我无法修改现有的 Gemfile;如上所述,我正在尝试模拟生产服务器。
  • 那么,Gemfile.lock 是否与您生产环境中的完全相同?

标签: ruby-on-rails ruby mysql2


【解决方案1】:

试试

bundle exec rake db:migrate

这将确保您正在执行“rake db:migrate”,并且 Gemfile 中列出的 gem 已加载且可用。如果你在没有“bundle exec”的情况下运行它,你可能只使用可用的系统 gem 来执行。

【讨论】:

    猜你喜欢
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 2012-12-20
    • 2011-12-19
    • 2013-12-15
    • 1970-01-01
    相关资源
    最近更新 更多