Home > Blockchain >  Render PostgreSQL cannot translate hostname to address in Django
Render PostgreSQL cannot translate hostname to address in Django

Time:12-16

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?

CodePudding user response:

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.

  • Related