如何将数据库附加到Heroku中的应用程序?

编程入门 行业动态 更新时间:2024-10-28 02:21:37
本文介绍了如何将数据库附加到Heroku中的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

现在我想将此数据库附加到我的应用程序,会被 heroku pg 命令所识别。

我可以在设置 DATABASE_URL 配置我的应用程序的var指向它,但 heroku pg 命令不能识别它。

其他信息:以前的数据库是共享的,而新的是一个生产。

解决方案

是否使用独立于应用程序的 postgres.heroku/ 网站?或者您是在Heroku控制面板中创建postgresql数据库?

rel =noreferrer> postgres.heroku/ ,您将 通过您的看到数据库> heroku pg:info 命令。然而,您可以将数据库添加到您的应用程序中:

  • 登录到 postgres.heroku/ 。
  • 点击要附加到您的数据库点击'连接设置',点击右上角的配置按钮。
  • 然后点击'URL'选项。
  • >
  • 复制你的数据库URL,这应该是类似于postgres:// blah:blah@ec2-23-23-122-88pute-1.amazonaws:5432 / omg。
  • 在您的应用程序的命令行中,运行 heroku config:set DATABASE_URL = postgres:// blah:blah @ ec2-23-23-122-88 pute-1.amazonaws: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.

    解决方案

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

    If you created your database on postgres.heroku/, 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:

  • Log into postgres.heroku/.
  • Click on the database you want to attach to your application.
  • Under 'Connection Settings', click the configuration button at the top right.
  • Then click the 'URL' option.
  • Copy your database URL, this should be something like "postgres://blah:blah@ec2-23-23-122-88pute-1.amazonaws:5432/omg".
  • In your application, on the command line, run heroku config:set DATABASE_URL=postgres://blah:blah@ec2-23-23-122-88pute-1.amazonaws: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中的应用程序?

    本文发布于:2023-10-17 12:46:12,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何将   应用程序   数据库   Heroku

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!