Rails ActiveRecord Connecting to Wrong Postgres Database

被刻印的时光 ゝ 提交于 2020-01-14 06:22:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!