导轨的ActiveRecord连接到错误的Postgres数据库 [英] Rails ActiveRecord Connecting to Wrong Postgres Database

查看:111
本文介绍了导轨的ActiveRecord连接到错误的Postgres数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的database.yml如下:

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

和我可以证实,该数据库phunt_development确实存在。然而,当我运行的ActiveRecord :: Base.connection.current_database 我得到发展不是 phunt_development 。我想不通,为什么Rails是坚持连接到一般开发数据库,​​这是污染的数据我从其他地方的应用程序。我想连接到 phunt_development

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.

推荐答案

问题是一个 $ DATABASE_URL 变量被设置在我的环境。当此设置,它将覆盖的database.yml 配置。解决方法:运行取消设置DATABASE_URL

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.

这篇关于导轨的ActiveRecord连接到错误的Postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆