开发者

Can't open rails console: production database not configured, establish_connection raises ActiveRecord::AdapterNotSpecified

开发者 https://www.devze.com 2023-01-14 20:51 出处:网络
My app works pretty much perfectly in production – the website part of it, at least. The problem only pops up when I SSH into my VPS and do \"rails c RAILS_ENV=production\". The console works fine in

My app works pretty much perfectly in production – the website part of it, at least. The problem only pops up when I SSH into my VPS and do "rails c RAILS_ENV=production". The console works fine in development mode.

I've had this problem before (or at least one that looks like it) and fixed it by adding "reconnect: true" to database.yml – but it didn't fix it this time around. Here's the start of the error output:

/home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': RAILS_ENV=production database is not configured (ActiveRecord::AdapterNotSpecified)
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:59:in `block (2 levels) in <class:Railtie>'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:57:开发者_JAVA技巧in `block in <class:Railtie>'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `instance_exec'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `run'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:50:in `block in run_initializers'

And for my production database settings:

production:
  adapter: mysql
  encoding: utf8
  database: tour_production
  pool: 5
  username: [user]
  password: [password]
  socket: /var/run/mysqld/mysqld.sock
  reconnect: true

I can't get my mind around why it works through passenger, but no luck with the console. Anyway, I'm using Rails 3, Ruby 1.9.2, Passenger and Nginx.

I've been doing some little stuff through Runner, which is annoying. I'd like to get this fixed. So thanks a bunch for any help.


When you are using the console you specify the environment as the first argument rather than as an environment variable. So:

ruby script/console production

will load the production environment.

Your error message is because it is looking for the environment RAILS_ENV=production rather than just production.


The latest Rails 3 way of doing this is simply:

bundle exec rails console -e production


@Shadwell is correct, however if you're after a consistent syntax you can set RAILS_ENV at the beginning like this:

RAILS_ENV=production rails console


I solved with run:

RAILS_ENV=production bundle exec rails c

more detail on link or stackoverflow

0

精彩评论

暂无评论...
验证码 换一张
取 消