ruby-on-rails - 如何将已部署的 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
解决方案
使用以下步骤:
1)在settings/Config Vars下添加DATABASE_URL
(完整的url用户名、密码、主机)。
2) 对于 Rails 应用程序,您应该使用db:schema:load, db:structure:load
ordb:migrate
代替db:setup
.
您可以使用 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
希望这可以帮助
推荐阅读
- html - WebGL - 使用网格作为倒置蒙版
- c# - 如果关系是一对多,我如何在我的外键列上插入值
- javascript - 如何将十六进制字符串从 node.js 中的 JSON 解析为十六进制数
- node.js - 为什么我无法使用 Nodejs 检索 json 数据?
- python - 连接池耗尽 psycopg2
- uitableview - tvOS 以编程方式将一个 UITableViewCell 的焦点更改为另一个
- vba - 在 VBA 中使用 dll 中的函数时出现运行时错误 48?
- jersey - 创建过滤器来处理异常 JERSEY
- javascript - 运行文件的 heroku 调度程序命令是什么?
- javascript - 'page-break-after: always' 在 ie11 上不起作用