简体   繁体   English

如何将部署的 rails 应用程序连接到现有的 Heroku 数据库

[英]How connect deployed rails app to exist Heroku database

I launched my Rails application on Heroku.我在 Heroku 上启动了我的 Rails 应用程序。 And I want to connect it to the database of an existing project of my friend, which is also deployed on Heroku.我想将它连接到我朋友的一个现有项目的数据库,该项目也部署在 Heroku 上。 A friend gave me credentials and url to the database.一位朋友给了我凭据和数据库的 url。 However, I do not understand how to connect my project to my friend's database.但是,我不明白如何将我的项目连接到我朋友的数据库。 I tried to change DABASE _URL but all is useless.我试图改变DABASE _URL但一切都没有用。 Also, credential data was placed in database.yml and when I run the heroku run db:setup in the heroku terminal i get此外,凭据数据被放置在database.yml ,当我在 heroku 终端中运行heroku run db:setup ,我得到

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

Use following steps:使用以下步骤:

1) Add DATABASE_URL (complete url username, password, host) under settings / Config Vars. 1)在设置/配置变量下添加DATABASE_URL (完整的url用户名、密码、主机)。

2) For Rails apps you should look to use db:schema:load, db:structure:load or db:migrate instead of db:setup . 2) 对于 Rails 应用程序,您应该考虑使用db:schema:load, db:structure:loaddb:migrate而不是db:setup

here is more info about issue https://help.heroku.com/63D7ALXT/why-am-i-seeing-user-does-not-have-connect-privilege-error-with-heroku-postgres-on-review-apps这里是关于问题的更多信息https://help.heroku.com/63D7ALXT/why-am-i-seeing-user-does-not-have-connect-privilege-error-with-heroku-postgres-on-review-应用

You can share a single Heroku Postgres database between multiple apps with the heroku addons:attach command您可以使用 heroku addons:attach 命令在多个应用程序之间共享单个 Heroku Postgres 数据库

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

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

hope this helps希望这可以帮助

The reason you cannot update DATABASE_URL is because it's currently pointing at another database without any auxiliary attachments.无法更新DATABASE_URL的原因是它当前指向另一个没有任何辅助附件的数据库。 This is a safety mechanism to prevent users from accidentally shooting themselves in the foot.这是一种安全机制,可防止用户意外射中自己的脚。 This should allow for your changes.这应该允许您进行更改。

  1. heroku addons:attach <addon name, eg postgresql-cloudy-12345> --as ORIGINAL_DB --app <app name>
    • This will create an additional attachment name so you don't lose reference to the original database这将创建一个额外的附件名称,因此您不会丢失对原始数据库的引用
  2. heroku addons:detach DATABASE_URL --app <app name>
    • This will remove the Heroku-managed DATABASE_URL config var.这将删除 Heroku 管理的DATABASE_URL配置变量。
  3. heroku config:set DATABASE_URL=<the connection string for the other database> --app <app name>
    • This sets DATABASE_URL to point at the other database which should put things into an operable state.*这将DATABASE_URL设置为指向另一个数据库,该数据库应该将事物置于可操作状态。*

* This caveat here is that this is a brittle configuration because hostnames can change for databases. * 这里需要注意的是,这是一个脆弱的配置,因为主机名可以更改为数据库。 If the db undergoes maintenance you will need to manually change the config var (ie repeat step 3).如果数据库进行维护,您将需要手动更改配置变量(即重复步骤 3)。

我通过转到 heroku.com 到我的应用程序然后设置然后配置变量解决了这种情况 DATABASE_URL 与 ORIGINAL_DB_URL 不同,所以我将 DATABASE_URL 更改为类似于 ORIGINAL_DB_URL 在我的情况下:postgres://quxhxkemlsfzzv:964c7 .... ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Rails应用程序部署到Heroku无法正常工作 - Deployed rails app to Heroku not working 将Scaffold rails应用程序部署到Heroku。 “ heroku打开”显示“您要查找的页面不存在” - Deployed Scaffold rails app to Heroku. “heroku open” gives “page you were looking for doesn't exist” 可以在不使用Heroku Toolbelt的情况下部署Rails应用程序吗? 如果是这样,怎么样? - Can a Rails app be deployed without using Heroku Toolbelt? If so, how? 如何删除部署在heroku上的Rails应用程序中的缓存页面 - how to delete cached page in rails app deployed on heroku 如何防止滥用抓取工具抓取部署在Heroku上的rails应用程序? - How to prevent abusive crawlers from crawling a rails app deployed on Heroku? 如何使用git复制rails app并部署到heroku - How to copy rails app using git and deployed to heroku 如何让rufus-scheduler使用部署到Heroku的Rails应用程序? - How to get rufus-scheduler working with a Rails app deployed to Heroku? 如何让用户在Heroku上部署的Rails应用程序中创建计划任务 - How to have users create scheduled tasks in rails app deployed on Heroku 将笔记本电脑上的本地rails应用程序连接到heroku数据库 - Connect local rails app on my laptop to heroku database Ruby on Rails应用程序已部署到heroku,但是应用程序出错? - Ruby on Rails app deployed to heroku but Application error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM