为数据库适配器指定'mysql',但未加载gem。将`gem'mysql'添加到你的Gemfile中

时间:2014-02-27 16:21:10

标签: ruby-on-rails ruby-on-rails-4

我在database.yml中设置了以下配置

production:
  adapter: mysql
  database: some_db
  host: localhost
  port: 3306
  pool: 5
  timeout: 15000
  username: root
  password: password
  socket: /var/lib/mysql/mysql.sock

我的Gemfile有

group :production do
  gem 'mysql', '~>2.8.1'
end

当我做一个宝石列表时,我得到以下内容:

bigdecimal (1.2.0)
builder (3.2.2)
bundler (1.5.3)
bundler-unload (1.0.2)
bunny (0.7.9)
chef (10.24.0)
chef-zero (1.7.3)
ci_reporter (1.9.1)
coderay (1.1.0)
diff-lcs (1.2.5)
erubis (2.7.0)
executable-hooks (1.3.1)
gem-wrappers (1.2.4)
hashie (2.0.5)
highline (1.6.20)
io-console (0.4.2)
ipaddress (0.8.0)
json (1.7.7)
method_source (0.8.2)
mime-types (2.1, 1.25.1)
minitest (4.7.5, 4.3.2)
minitest-chef-handler (1.0.2)
mixlib-authentication (1.3.0)
mixlib-cli (1.4.0)
mixlib-config (2.1.0)
mixlib-log (1.6.0)
mixlib-shellout (1.3.0)
moneta (0.6.0)
net-ssh (2.8.0)
net-ssh-gateway (1.2.0)
net-ssh-multi (1.1)
ohai (6.20.0)
polyglot (0.3.4)
pry (0.9.12.6)
psych (2.0.0)
puma (1.6.3)
rack (1.5.2)
rake (0.9.6)
rdoc (4.0.0)
rest-client (1.6.7)
rubygems-bundler (1.4.2)
rvm (1.11.3.9)
slop (3.4.7)
systemu (2.5.2)
test-unit (2.0.0.0)
treetop (1.4.15)
uuidtools (2.1.4)
yajl-ruby (1.2.0)

当我进行捆绑展示时,会显示mysql (2.8.1)

当我尝试运行bundle exec rake db:migrate RAILS_ENV=production时,我收到以下错误

rake aborted!
Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile.
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:58:in `rescue in resolve_hash_connection'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:55:in `resolve_hash_connection'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:30:in `spec'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activerecord-4.0.3/lib/active_record/connection_handling.rb:39:in `establish_connection'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activerecord-4.0.3/lib/active_record/railtie.rb:176:in `block (2 levels) in <class:Railtie>'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `each'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activerecord-4.0.3/lib/active_record/railtie.rb:174:in `block in <class:Railtie>'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:30:in `instance_exec'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:30:in `run'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/initializable.rb:54:in `run_initializers'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/application.rb:215:in `initialize!'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/config/environment.rb:7:in `<top (required)>'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `block in require'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/application.rb:189:in `require_environment!'
/var/www/rack_apps/wolfe_manager/releases/c3115a7066257a3c72016438c99a13bb6d88e989e635f81942b4a6060d91a256/vendor/cache/ruby/2.0.0/gems/railties-4.0.3/lib/rails/application.rb:250:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

配置 Rails -4 红宝石 - 2 请帮忙吗?

1 个答案:

答案 0 :(得分:-1)

应该为所有环境设置数据库驱动程序,而不仅仅是production。它没有安装在您的开发环境中,因为它不被认为是必需的。