问题
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
.
回答1:
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
.
来源:https://stackoverflow.com/questions/17417852/rails-activerecord-connecting-to-wrong-postgres-database