首页 > 解决方案 > 如何将已部署的 Rails 应用程序连接到现有 Heroku 数据库

问题描述

我在 Heroku 上启动了我的 Rails 应用程序。我想将它连接到我朋友的现有项目的数据库,该项目也部署在 Heroku 上。一位朋友给了我数据库的凭据和 url。但是,我不明白如何将我的项目连接到我朋友的数据库。我试图改变DABASE _URL,但一切都没用。此外,凭证数据被放入,database.yml当我heroku run db:setup在 heroku 终端中运行时,我得到

FATAL: permission denied for database "postgres" DETAIL: User does not have CONNECT privilege. Couldn't create '*************' database. Please check your configuration. rake aborted! PG::ConnectionBad: FATAL: permission denied for database "postgres" DETAIL: User does not have CONNECT privilege

标签: ruby-on-railspostgresqlherokucredentials

解决方案


使用以下步骤:

1)在settings/Config Vars下添加DATABASE_URL(完整的url用户名、密码、主机)。

2) 对于 Rails 应用程序,您应该使用db:schema:load, db:structure:loadordb:migrate代替db:setup.

这是有关问题的更多信息https://help.heroku.com/63D7ALXT/why-am-i-seeing-user-does-not-have-connect-privilege-error-with-heroku-postgres-on-review-应用

您可以使用 heroku addons:attach 命令在多个应用程序之间共享单个 Heroku Postgres 数据库

heroku addons:attach my-originating-app::DATABASE --app new_app

有关更多信息,请在此处查看https://devcenter.heroku.com/articles/heroku-postgresql#sharing-heroku-postgres-between-applications

希望这可以帮助


推荐阅读