我的gemfile有这一行:
gem 'mysql2', group: :production
但是当我从命令行运行这个命令时,我得到了这个错误:rails r "puts Rails.env"
/Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:50:in `establish_connection'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activerecord-4.2.6/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `each'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/activerecord-4.2.6/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `call'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
from /Users/cgunnels/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/cgunnels/.rvm/gems/ruby-2.2.2@global/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
...
rest of stack trace
顺便说一句:我还没弄明白为什么mysql2不能安装。我已经尝试了几个修复每个堆栈溢出搜索,但没有骰子。
更新:我没有提到,但我想在开发环境中。
发布于 2018-07-06 03:18:17
您可能会收到错误,因为当您不在生产环境中时,没有数据库驱动程序。
https://stackoverflow.com/questions/51198189
复制相似问题