如何将数据库附加到Heroku中的应用程序 [英] how can I attach a database to an app in Heroku

查看:209
本文介绍了如何将数据库附加到Heroku中的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Heroku的Postgres插件,我从Heroku Postgres插件页面创建了一个新的生产数据库。
我没有使用我的应用程序的资源页面直接添加到我的应用程序。



现在我想将这个数据库附加到我的应用程序,



我可以在设置 DATABASE_URL 之后使用数据库btw > config var我的应用程序指向它,但 heroku pg 命令还不能识别它。



附加信息:上一个数据库

解决方案

p>您是使用与应用无关的 https://postgres.heroku.com/ 网站添加数据库吗?



如果您在 https://postgres.heroku.com/ ,您将不会通过 heroku pg:info 命令。但是,你可以做什么将数据库添加到应用程序中:


  1. 登录 https://postgres.heroku.com/

  2. 点击要附加到您的数据库

  3. 在连接设置下,点击右上角的配置按钮。
  4. >
  5. 复制数据库URL,应该是postgres:// blah:blah@ec2-23-23-122-88.compute-1.amazonaws.com:5432 / omg。

  6. 在您的应用程序中,在命令行中,运行 heroku config:set DATABASE_URL = postgres:// blah:blah @ ec2-23-23-122-88 .compute-1.amazonaws.com:5432 / omg

到应用程序中的 DATABASE_URL 环境变量。这是在将数据库本地设置到应用程序时默认使用的变量,因此理论上,分配此值应该对您来说很合适。


I'm using Heroku's Postgres addon, and I created a new production database from the Heroku Postgres addon page. I Didn't add it directly to my App using the Resources page of my App.

Now I want to attach this database to my App so it'll be recognized by the heroku pg command.

I'm able to use the database btw after setting the DATABASE_URL config var of my app to point to it, but heroku pg command doesn't recognize it yet.

Additional info: The previous database was Shared, and the new one is a Production.

Thanks

解决方案

Did you add the database using the app-independent https://postgres.heroku.com/ site? Or did you just create a postgresql database in your Heroku control panel?

If you created your database on https://postgres.heroku.com/, you will not see the database via your heroku pg:info command. What you can do to add your database to your application, however, would be to:

  1. Log into https://postgres.heroku.com/.
  2. Click on the database you want to attach to your application.
  3. Under 'Connection Settings', click the configuration button at the top right.
  4. Then click the 'URL' option.
  5. Copy your database URL, this should be something like "postgres://blah:blah@ec2-23-23-122-88.compute-1.amazonaws.com:5432/omg".
  6. In your application, on the command line, run heroku config:set DATABASE_URL=postgres://blah:blah@ec2-23-23-122-88.compute-1.amazonaws.com:5432/omg

What we did there was assign your database to the DATABASE_URL environment variable in your application. This is the variable that's used by default when you provision databases locally to your application, so theoretically, assigning this value should work just fine for you.

这篇关于如何将数据库附加到Heroku中的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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