Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Render PostgreSQL cannot translate hostname to address in Django

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading