轨道/ ActiveRecord的 - AdapterNotSpecified,即使它是 [英] Rails / ActiveRecord - AdapterNotSpecified, even though it is
问题描述
我做的 Ruby on Rails的教程。,在前三章它使用SQLite的,但后来却建议在使用PostgreSQL开发更容易的Heroku部署。编辑后,我的的database.yml
和的Gemfile
来使用PG,而不是sqlite3的,似乎工作 - 用耙时除外运行测试。它弹出一个 AdapterNotSpecified
错误。
I'm doing the Ruby on Rails Tutorial. For the first three chapters it uses SQLite, but later it suggests using PostgreSQL on development for easier Heroku deploys. After editing my database.yml
and Gemfile
to use pg instead of sqlite3, it seems to work - except when using Rake to run a test. It pops out an AdapterNotSpecified
error.
C:/Ruby/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/lib/active_record/
connection_adapters / connection_specification.rb:52:在resolve_hash_connection:
数据库配置不指定适配器(的ActiveRecord :: AdapterNotSpecif
IED)
C:/Ruby/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/lib/active_record/
connection_adapters/connection_specification.rb:52:in resolve_hash_connection':
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecif
ied)
等。
在database.yml中指定一个适配器,像这样:
The database.yml specifies an adapter, like so:
development:
adapter: postgresql
host: localhost
username: nekkoru
password: derpderp
database: development
encoding: UTF8
这是怎么回事?我在Windows 7 64位系统,红宝石1.9.3,Rails的4.0.0,PostgreSQL的9.3.0.1。
What's going on? I'm on Windows 7 x64, Ruby 1.9.3, Rails 4.0.0, PostgreSQL 9.3.0.1.
推荐答案
您没有定义数据库的测试环境。您的database.yml
应该是这样的:
You did not define the database for the test environment. You database.yml
should look like:
development:
adapter: postgresql
host: localhost
username: nekkoru
password: derpderp
database: development
encoding: UTF8
test:
adapter: postgresql
host: localhost
username: nekkoru
password: derpderp
database: test # or whatever the name is
encoding: UTF8
这篇关于轨道/ ActiveRecord的 - AdapterNotSpecified,即使它是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!