将 Heroku App 连接到外部数据库
Connecting Heroku App to outside database
我已经将我的应用程序部署到 Heroku,我希望 Heroku 连接到外部 PostgreSQL 数据库。
这是我的Railsdatabase.yml
production:
url: "postgres://postgres:@127.0.0.1:5432/postgres"
adapter: PostgreSQL
此数据库在开发环境中运行良好。但是当在 Heroku 上时,我收到连接被拒绝的错误。这可能是什么问题?
Heroku 忽略您的 database.yml 生产设置并使用它自己的。 Heroku 使用 ENV var DATABASE_URL 来创建连接。我认为你可以实现你的目标,如果你使用与他们用来连接到 heroku pg 相同的结构。
在 heroku 应用程序设置中添加环境变量:
DATABASE_URL=postgres://username:password@your-host/db_name
在此处添加环境变量:https://dashboard.heroku.com/apps/your-app-name/settings
点击 "Reveal Config Vars" 并添加 DATABASE_URL
或通过 CLI:
heroku config:set DATABASE_URL=postgres://username:password@your-host/db_name --app your-app-name
确保安装了 gem pg
!
我已经将我的应用程序部署到 Heroku,我希望 Heroku 连接到外部 PostgreSQL 数据库。
这是我的Railsdatabase.yml
production:
url: "postgres://postgres:@127.0.0.1:5432/postgres"
adapter: PostgreSQL
此数据库在开发环境中运行良好。但是当在 Heroku 上时,我收到连接被拒绝的错误。这可能是什么问题?
Heroku 忽略您的 database.yml 生产设置并使用它自己的。 Heroku 使用 ENV var DATABASE_URL 来创建连接。我认为你可以实现你的目标,如果你使用与他们用来连接到 heroku pg 相同的结构。
在 heroku 应用程序设置中添加环境变量:
DATABASE_URL=postgres://username:password@your-host/db_name
在此处添加环境变量:https://dashboard.heroku.com/apps/your-app-name/settings
点击 "Reveal Config Vars" 并添加 DATABASE_URL
或通过 CLI:
heroku config:set DATABASE_URL=postgres://username:password@your-host/db_name --app your-app-name
确保安装了 gem pg
!