[英]Can't start rails console in production
I'm getting this error when trying to start the rails console on my project: 尝试在我的项目上启动Rails控制台时出现此错误:
/home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:129:in `establish_connection'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/base.rb:721:in `<top (required)>'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/railtie.rb:41:in `block in <class:Railtie>'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `call'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `block in load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `each'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/engine.rb:429:in `block in load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/application/railties.rb:8:in `each'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/application/railties.rb:8:in `all'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/engine.rb:429:in `load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/application.rb:153:in `load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/commands/console.rb:27:in `start'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Here is my database.yml file (unmodified from the default one): 这是我的database.yml文件(与默认文件相同):
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
I don't believe this is a system-specific issue since it occurs both on my development environment (Fedora 17 laptop) and production environment (Debian 6 VPS). 我不认为这是系统特定的问题,因为它同时出现在我的开发环境(Fedora 17笔记本电脑)和生产环境(Debian 6 VPS)上。 On the VPS, nginx+unicorn starts and serves without issue in production.
在VPS上,nginx + unicorn启动并在生产中正常运行。 What might the cause be?
原因可能是什么?
Instead of rails console RAILS_ENV=production
: 代替
rails console RAILS_ENV=production
:
Use rails console production
or shorter rails c production
. 使用
rails console production
或较短的rails c production
。
The value following the call to rails console will be taken as the environment, thus it thinks "RAILS_ENV=production" is the name of the environment it should use, instead of "production". 调用rails控制台后的值将用作环境,因此它认为“ RAILS_ENV = production”是它应使用的环境的名称,而不是“ production”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.