Hi,
I’m trying to connect a Django app to my Postgres instance. I’ve tried both the typical Django way, and using the dj-database-url library. My backend app and DB are in the same region.
When trying to connect to the internal render DB url, I get:
psycopg2.OperationalError: could not translate host name "dpg-ccudiaien0hklj3l3fa0-a" to address: Name or service not known
Here’s what the DB connection approaches look like:
dj-database-url (I know that Render provides a stringified version)
DB_NAME = os.getenv("DB_NAME", "db")
DB_USER = os.getenv("DB_USER", "kenny")
DB_HOST = os.getenv("DB_HOST", "localhost")
DB_PASSWORD = os.getenv("DB_PASSWORD", "")
DB_PORT = os.getenv("DB_PORT", 5432)
DATABASES = {
'default': dj_database_url.parse(f'postgres://{DB_USER}:{DB_PASSWORD}@{DB_HOST}/{DB_NAME}')
}
And
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.getenv("DB_NAME", "db"),
"USER": os.getenv("DB_USER", "kenny"),
"HOST": os.getenv("DB_HOST", "localhost"),
"PASSWORD": os.getenv("DB_PASSWORD", ""),
"PORT": os.getenv("DB_PORT", 5432),
}
}
Finally, the way it is shown in the “Deploy Django” docs:
DATABASES = {
'default': dj_database_url.config(default=os.getenv('DATABASE_URL', ""), conn_max_age=60)
}
First 2 seem to have no issue locally, I’ve only tried the last on Render and I get a Django error:
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
Anyway, I expect 1 of the first 2 to work regardless.
I am deploying to Render using a Docker container, not sure if it is something to do with the Docker networking? Any ideas what might be causing this?