[英]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:load
或db: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.
这应该允许您进行更改。
heroku addons:attach <addon name, eg postgresql-cloudy-12345> --as ORIGINAL_DB --app <app name>
heroku addons:detach DATABASE_URL --app <app name>
DATABASE_URL
config var.DATABASE_URL
配置变量。heroku config:set DATABASE_URL=<the connection string for the other database> --app <app name>
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.