Where to set the DATABASE_URL environment variable on Heroku

478 views
Skip to first unread message

Tim Johnson

unread,
Dec 6, 2019, 8:40:48 PM12/6/19
to MLDjango
Despite the voluminous Heroku documentation I am unable to establish
where to initialize the DATABASE_URL that would establish credentials
for my deployed database.

Heroku's documentation uses the following example

DATABASE_URL=$(heroku config:get HEROKU_POSTGRESQL_TIMS_URL -a timsapp)

But I am not clear where this initialization code should live

would it be in the procfile? If so, what process should I use. Release?
Worker?

OR

Would it be in an .env file?

Using django 2.1.5, python 3.7

examples welcome :)

thanks

--
Tim
tj49.com

Jorge Gimeno

unread,
Dec 7, 2019, 1:09:48 AM12/7/19
to django...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a02698e8-e71a-5d42-728d-4c6d012bbb84%40akwebsoft.com.
 
I believe DATABASE_URL is set on Heroku itself as a configuration variable.  If you provision the database in Heroku, it will be set for you.  See here:  https://devcenter.heroku.com/articles/heroku-postgresql#provisioning-heroku-postgres

-Jorge
 

Tim Johnson

unread,
Dec 7, 2019, 11:23:39 AM12/7/19
to django...@googlegroups.com


On 12/6/19 9:09 PM, Jorge Gimeno wrote:
On Fri, Dec 6, 2019 at 5:40 PM Tim Johnson <t...@akwebsoft.com> wrote:
Despite the voluminous Heroku documentation I am unable to establish
where to initialize the DATABASE_URL that would establish credentials
for my deployed database.

Heroku's documentation uses the following example

DATABASE_URL=$(heroku config:get HEROKU_POSTGRESQL_TIMS_URL -a timsapp)

But I am not clear where this initialization code should live

would it be in the procfile? If so, what process should I use. Release?
Worker?

OR

Would it be in an .env file?
... snip ...
I believe DATABASE_URL is set on Heroku itself as a configuration variable.  If you provision the database in Heroku, it will be set for you.  See here:  https://devcenter.heroku.com/articles/heroku-postgresql#provisioning-heroku-postgres

Thank you Jorge, I have read that section too:

The following is highlighted as a warning on that:

"""

The value of your app’s DATABASE_URL config var might change at any time.

You should not rely on this value either inside or outside your Heroku app.

"""

that is precisely why I have asked this question.

more discussion of this issue is found at https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku

and a search for "DATABASE_URL=$("  will give an example of how to set DATABASE_URL from the Heroku command line.

That approach begs for a script but I am unsure of what script file to use. .env or Procfile or some other.

Thanks again Jorge

-- 
Tim
tj49.com

Dvs Khamele

unread,
Dec 7, 2019, 12:47:36 PM12/7/19
to django...@googlegroups.com
Hi do you hire contract based python/django freelancer?
 I can help you in this 
Best Regards, 
Divyesh Khamele

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages