如何更改heroku上的database_url? [英] How to change database_url on heroku?

查看:150
本文介绍了如何更改heroku上的database_url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据 Heroku 上的两个应用程序之间共享数据库-between-2-apps-in-heroku>在Heroku中的2个应用程序之间共享数据库,但在第二个应用程序上设置database_url会给出错误:

  $ heroku config:add DATABASE_URL = postgres:// ... 
设置配置变量并重新启动pacific-headland-1960 ...失败
!无法销毁最后一次附加到结算应用程序的资源爱情 - 小巧 - 5807


解决方案

DATABASE_URL 目前正在存储您的第二个应用程序与其配置数据库的连接,Heroku可以阻止您删除,因为没有其他引用。 >

首先,删除第二个应用程序的数据库。 其中的任何内容都将被销毁。

  heroku addons:destroy heroku-postgresql:< your DB层> --app<您的第二个应用程序> 

如果这些是新应用程序,则您的数据库层可能 hobby-dev ,但您可以通过运行 heroku addons --app<您的第二个应用程序> 来检查。



然后,您可以在第二个应用程序中设置 DATABASE_URL



如果您想要将第二个应用连接到两个数据库,您需要将第一个应用的数据库URL存储在不同的环境变量中,并更新第二个应用的代码以使用它。



< hr>

与您的问题无关,您刚将数据库凭证粘贴到公共空间中。您应该使用 heroku pg:凭证--reset --app<您的第一个应用程序>



文档: https://devcenter.heroku.com/articles/heroku-postgresql


I am trying to share a database between two apps on Heroku according to Share database between 2 apps in Heroku but setting up database_url on the second app gives an error:

$ heroku config:add DATABASE_URL=postgres://...
Setting config vars and restarting pacific-headland-1960... failed  
 !    Cannot destroy last attachment to billing app for resource loving-subtly-5807

解决方案

DATABASE_URL is what's currently storing your second app's connection to its provisioned DB, which Heroku is kindly preventing you from deleting because there are no other references to it.

First, remove the second application's DB. Anything in it will be destroyed.

heroku addons:destroy heroku-postgresql:<your DB tier> --app <your second app>

If these are new apps, your DB tier is probably hobby-dev, but you can check for it by running heroku addons --app <your second app>.

Then, you'll be able to set DATABASE_URL on the second app.

If you want to have the second app connected to both DBs, you'll need to store the first app's DB URL in a different environment variable and update your second app's code to use it.


Unrelated to your question, you've just pasted your DB credentials into a public space. You should roll them with heroku pg:credentials --reset --app <your first application>.

Docs: https://devcenter.heroku.com/articles/heroku-postgresql

这篇关于如何更改heroku上的database_url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆