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:in resolve_hash_connection':
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecif
ied)
etc.
The database.yml specifies an adapter, like so:
development:
adapter: postgresql
host: localhost
username: nekkoru
password: derpderp
database: development
encoding: UTF8
What's going on? I'm on Windows 7 x64, Ruby 1.9.3, Rails 4.0.0, PostgreSQL 9.3.0.1.
You did not define the database for the test environment. Your database.yml
file 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
Indentation was the culprit for me.
Rails it seems has a strict way of reading db type (development or production) and the db settings (adapter, host, username, etc etc) from the yml file.
But of course the ActiveRecord error msg was overkill.. it made it look like I was missing a gem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With