Sam Stern
Sam Stern

Reputation: 25134

Rails ActiveRecord Connecting to Wrong Postgres Database

My database.yml is as follows:

development:
  adapter: postgresql
  database: phunt_development
  username: <%= ENV['PG_USER'] %>
  password: <%= ENV['PG_PASS'] %>
  host: localhost
  pool: 5
  timeout: 5000

And I can confirm that the database phunt_development does exist. However when I run ActiveRecord::Base.connection.current_database I get development not phunt_development. I can't figure out why Rails is insisting on connecting to the general development database, which is polluted with data I have from other local apps. I want to connect to phunt_development.

Upvotes: 0

Views: 1545

Answers (1)

Sam Stern
Sam Stern

Reputation: 25134

Issue was a $DATABASE_URL variable was set in my environment. When this is set, it overrides the configuration in database.yml. Solution: run unset DATABASE_URL.

Upvotes: 3

Related Questions