pythondjangopostgresqlrailway

django.db.utils.OperationalError: could not translate host name "postgres.railway.internal"


django.db.utils.OperationalError: could not translate host name "postgres.railway.internal" to address: nodename nor servname provided, or not known

My Django project was working great until I changed the setting.py file to deploy it in Railway, using the variables Railway provides.

Since then, I can't runserv or migrate, that I get this error...

Here are the database settings changed to use the Railway variables:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'railway',
        'USER': 'postgres',
        'PASSWORD': DB_PASSWORD_RAIL,
        'HOST': 'postgres.railway.internal',
        'PORT': '5432',
    }
}

Error when I runserver or migrate:

django.db.utils.OperationalError: could not translate host name "postgres.railway.internal" to address: nodename nor servname provided, or not known

Solution

  • Go to settings and under public networking find an url like this viaduct.proxy.rlwy.net:xxxx which is equivalent to host:port

    Use the first part as your host and later number as your port number. It should work.