I\'m trying to use rails 4.2.6 to develop an app. I\'m trying to use postgres for database. Server starts fine but when I try loading a page it throws this \"No connection p
In my case, the config/database.yml
was taking variables from the environment:
# ...
test:
<<: *default
database: <%= ENV.fetch("DB_NAME") %>_test
username: <%= ENV.fetch("DB_USER") %>
password: <%= ENV.fetch("DB_PASS") %>
# ...
The error was coming when the new terminal window where I was running the bundle exec rails spec
did not have those variables initialized.
Doing,
$ export DB_NAME=mydb
$ export DB_USER=myuser
$ export DB_PASS=mypass
$ bundle exec rails spec
fixed the issue.
For PostgreSQL your database.yml
file should look something like that:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: your_db_name
Also make sure that you have the gem installed: in your Gemfile:
gem 'pg'
Finally, restart your server.
Hope that helps
Edit: I almost forgot, make sure you have your PostgresSQL running, check this link for download and setup.
I've encountered the same problem when I try to access the Model before creating the DataBase.
Make sure you run rake db:migrate
at least once.
If you already run migration then check the Database as mentioned in previous answers.