为什么我的rails应用程序引发“数据库配置未指定适配器(ActiveRecord :: AdapterNotSpecified)”错误?

时间:2015-02-17 17:04:06

标签: ruby-on-rails-3.2 pg

我刚刚使用Capistrano在ruby 2.2的新gemset中更新了我的生产rails应用程序,我收到以下错误:

/var/www/odpf/shared/bundle/ruby/2.2.0/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)

这是我的database.yml:

production:
  host: localhost
  port: xxxx
  adapter: postgresql
  encoding: utf8
  database: odpf
  pool: 5
  username: xxxxxx
  password: xxxxxx

我不明白为什么我收到此错误,因为我的database.yml在capisrano更新之前和之后都没有改变。

所有宝石都存储在/var/www/odpf/shared/bundle/ruby/2.2.0/gems中。

如果我运行bundle exec gem list

,则会出现postgresql的pg gem

我的数据库正在运行,因为我可以使用database.yml的用户从psql连接到它:\c odpf xxxxxx 127.0.0.1 xxxx

所以我不明白出了什么问题。

当我运行bundle exec rails c

时,这也是一个更大的跟踪错误的摘录
/var/www/odpf/current$ bundle exec rails c
/var/www/odpf/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.21/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
/var/www/odpf/shared/bundle/ruby/2.2.0/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
    from /var/www/odpf/shared/bundle/ruby/2.2.0/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'

它正在谈论ActiveSupport中的循环引用,也许它有助于解决这个问题?

=== UPDATE ===

我只是将测试和开发部分添加到我的database.yml中,错误消息确实发生了变化。看起来有人认为他处于测试模式:

bundle exec rails c

/var/www/odpf/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.21/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
/var/www/odpf/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- test/unit/testcase (LoadError)

我无法弄清楚为什么会发生这种情况?因为我的虚拟主机中有RailsEnv production行,并且在capistrano更新之前它运行正常。

1 个答案:

答案 0 :(得分:0)

事实上一切都是正确的。

关于rails控制台,它总是在开发模式下执行,除非您特别询问生产参数。

关于我的问题,我不得不停止postgresql,停止apache2,并修改我的.gitignore文件以再次跟踪tmp / restart.txt文件并使其再次成为我的存储库的一部分(通过复制它,删除旧的,git add -Agit push ...)。

然后启动postgresql和apache2。

很抱歉这个问题。

相关问题