connect postgress db to my django app
Anonymous
HOBBYOP

a year ago

Im trying to connect my app to the postgres instance and it keeps failing since the host is not known although working with the public url it works but that is not how Id wish to have it connected

# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

POSTGRES_USER = config("PGUSER")  # Matches PGUSER in .env
POSTGRES_PASSWORD = config("POSTGRES_PASSWORD")  # Matches POSTGRES_PASSWORD in .env
POSTGRES_PORT = config("PGPORT")  # Matches PGPORT in .env
POSTGRES_DB = config("PGDATABASE")  # Matches PGDATABASE in .env
POSTGRES_HOST = config("PGHOST")  # Matches PGHOST, which is set as RAILWAY_PRIVATE_DOMAIN in .env

# Construct the database URL
PSQL_URL = f"postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}"
PSQL_URL = config("PSQL_URL")
# Django database settings
DATABASES = {
    "default": dj_database_url.config(default=PSQL_URL, conn_max_age=600),
}

View Deploy details

ⓘ Deployment information is only viewable by project members and Railway employees.

Solved

1 Replies

a year ago

You can not use the private network during build.

Wait until runtime to do whatever you need to do with the database before then starting your app.


Status changed to Solved brody over 1 year ago


Loading...