Nin*_*Boy 22 postgresql ruby-on-rails heroku heroku-postgres
我准备好了一个外部数据库,现在想用我的heroku应用程序使用该数据库.但是我无法编辑配置变量.我尝试使用GUI,其中说,无法覆盖附件值DATABASE_URL.虽然我也尝试使用CLI.我使用了命令:heroku config:addDATABASE_URL ="postgresql:// username:password @ IP:PORT".但是,这会引发错误........不是heroku命令.
0bs*_*r07 30
在尝试了大多数这些答案后,我在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=
Run Code Online (Sandbox Code Playgroud)
小智 14
另一种不需要分离的方法(可能不是转换的预期结果)是简单地附加新数据库然后将其提升,Heroku文档明确指出这是一种设置方法DATABASE_URL
.
heroku addons:attach heroku-postgresql -a <app_name>
heroku pg:promote heroku-postgresql -a <app_name>
Run Code Online (Sandbox Code Playgroud)
我今天遇到了同样的情况,当我需要更改postgres
为postgis
. 分离对我不起作用,所以我这样做是为了database.yml
:
production:
url: <%= ENV['DATABASE_URL'].sub(/^postgres/, "postgis") %>
Run Code Online (Sandbox Code Playgroud)
https://github.com/rgeo/activerecord-postgis-adapter/issues/214。
小智 5
SQLAlchemy 1.4.x 删除了对 Heroku Postgres 使用的 postgres:// URI 方案的支持 ( https://github.com/sqlalchemy/sqlalchemy/issues/6083 )。为了保持兼容性,请在与 SQLAlchemy 设置连接之前执行以下操作:
import os
import re
uri = os.getenv("DATABASE_URL") # or other relevant config var
if uri.startswith("postgres://"):
uri = uri.replace("postgres://", "postgresql://", 1)
# rest of connection code using the connection string `uri`
Run Code Online (Sandbox Code Playgroud)
这将允许您使用 SQLAlchemy >= 1.4.x 连接到 Heroku Postgres 服务
归档时间: |
|
查看次数: |
11681 次 |
最近记录: |