1
我在database.yml中設置以下配置爲數據庫適配器指定'mysql',但未加載gem。添加'寶石「mysql'`您的Gemfile
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 幫助嗎?
但是這就是爲什麼我指定RAILS_ENV =生產..所以它只拾取生產 – kauschan
這是一個變量傳入,而不是一個真正的環境變量。如果你將它推到前面,它可能會工作,比如'RAILS_ENV =生產捆綁包exec rake db:migrate',其中bundler有機會解釋它。通常情況下,您應該在shell配置文件中正確地在生產服務器上設置「RAILS_ENV」和/或「RACK_ENV」。 – tadman
感謝您讓我知道正確的方式......我嘗試將其他env添加到yaml文件中......並且RAILS_ENV = production bundle exec rake db:migrate ...我知道它正在拾取生產ENV配置...但不知道爲什麼它找不到寶石 – kauschan