postgresql 如何更改 Heroku 应用程序的 DATABASE_URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35061914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change DATABASE_URL for a heroku application
提问by Ninja Boy
I wanted to use an external Database with my heroku application. But I'm unable to edit the configuration cariables. I tried using GUI, Which says, Cannot overwrite attachment values DATABASE_URL. While I tried using CLI as well. I used the command: heroku config:addDATABASE_URL="postgresql://username:password@IP:PORT"
. However, this throws an error ... is not a heroku command.
我想在我的 heroku 应用程序中使用外部数据库。但我无法编辑配置 cariables。我尝试使用 GUI,上面写着无法覆盖附件值 DATABASE_URL。虽然我也尝试使用 CLI。我使用了命令:heroku config:addDATABASE_URL="postgresql://username:password@IP:PORT"
. 但是,这会引发错误... is not a heroku command.
回答by 0bserver07
After trying out most these answers, I came across an update in 2016, here: the database needs to be detached first, then update the variable of the DATABASE_URL.
在尝试了大多数这些答案之后,我在 2016 年遇到了一个更新,这里是:需要先分离数据库,然后更新 DATABASE_URL 的变量。
heroku addons:attach heroku-postgresql -a <app_name> --as HEROKU_DATABASE
heroku addons:detach DATABASE -a <app_name>
heroku config:add DATABASE_URL=
回答by andrewjt
An alternative method which does not require detaching (which may not be a desired outcome of the switch) is to simply attach the new database and then promote it, which the Heroku Documentsexplicitly states as a way to set the DATABASE_URL
.
另一种不需要分离(这可能不是切换的预期结果)的替代方法是简单地附加新数据库然后提升它,Heroku 文档明确指出这是设置DATABASE_URL
.
heroku addons:attach heroku-postgresql -a <app_name>
heroku pg:promote heroku-postgresql -a <app_name>
回答by Simone Carletti
As explained in this article, the correct syntax to set/add a configuration variable is
如本文所述,设置/添加配置变量的正确语法是
$ heroku config:set DATABASE_URL="postgresql://username:password@IP:PORT"
However, it looks like (see the comments) the DATABASE_URL
has been deprecated and trying to update it will trigger an error.
但是,它看起来(见评论)DATABASE_URL
已被弃用,尝试更新它会触发错误。
回答by Tan Duong
I got the very same situation today when I need to change postgres
to postgis
. Detach doesn't work for me so I done this to database.yml
:
我今天遇到了同样的情况,当我需要更改postgres
为postgis
. 分离对我不起作用,所以我这样做是为了database.yml
:
production:
url: <%= ENV['DATABASE_URL'].sub(/^postgres/, "postgis") %>
https://github.com/rgeo/activerecord-postgis-adapter/issues/214.
https://github.com/rgeo/activerecord-postgis-adapter/issues/214。
回答by Ninja Boy
Solved it. Just for the reference of the users who have the same issue or want to have a similar implementation. Here's the workaround which worked for me.
解决了。仅供有相同问题或想要类似实现的用户参考。这是对我有用的解决方法。
Heroku no more overwrites databse.yml, so I just modified the DATBASE_URL in the database.yml and pushed it :)
Heroku 不再覆盖 databse.yml,所以我只是修改了 database.yml 中的 DATBASE_URL 并将其推送:)
It worked too!
它也起作用了!
Source : https://discussion.heroku.com/t/rails-4-1-database-yml-no-longer-overwritten-on-heroku/550
来源:https: //discussion.heroku.com/t/rails-4-1-database-yml-no-longer-overwritten-on-heroku/550
回答by Andrei Erdoss
Based on the Heroku docsthis is how you would share a database with multiple apps.
根据Heroku 文档,这是与多个应用程序共享数据库的方式。
heroku addons:attach my-originating-app::DATABASE --app sushi