Render PostgreSQL cannot translate hostname to address in Django

Question:

With Render, I would like to use their free PostgreSQL plan to host my database. I am using Django and I got confused what to use as a HOST. The dashboard on Render provides me with an external database url postgres://{given_username_by_render}:******-a.oregon-postgres.render.com/{database_name} if i use this link as a HOST in the databases settings as

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'name',
        'USER': 'username',
        'HOST' : 'postgres://{given_username_by_render}:******-a.oregon-postgres.render.com/{database_name}',
        'PASSWORD': env('PSGS'),
    }
}

I get this error while making migrations. I had used elephantsql before and they give me a simple host url like tiny.db.elephantsql.com which is plugged in HOST name and it worked but not in this case of using Render

RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not translate host name 
"postgres://USER:PASSWORD@EXTERNAL_HOST:PORT/DATABASE"
to address: Unknown server error

My main question is, What do i use as the HOST name in database settings in django? Or am I doing this all wrong? If you do not have experience with Render then can you recommend me places where i can learn about things like these?

Asked By: A-d-ash

||

Answers:

The host is just ******-a.oregon-postgres.render.com, everything that comes after @ and before /{database_name}.

Generally, the URL will have this structure:

postgres://{user}:{password}@{host}:{port}/{database}

If you prefer, you could use the URL directly via dj-database-url. If Render populates the DATABASE_URL environment variable for you, this library will work right out of the box with very little configuration required.

Answered By: Chris
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.