Django PostgreSQL template database not working

noahtuneslaunchpadyt
HOBBY

8 months ago

My connections to Postgres servers are failing on project generated from the Django template.

I created a new project using the Django template, the 3rd top most recommended template. After the empty project successfully deploys, I try seeing if I can access the database from the railway CLI to create a super user.

I clone the git repository onto my computer.

I use "railway link" to link the repo to my project.

"railway status" indicates everything is deployed.

"railway variables" indicates that I'm using a railway database on PGPORT 5432 with the PGHOST "postgres.railway.internal".

"python manage.py runserver" works locally.

"railway run python manage.py runserver" gives

django.db.utils.OperationalError: could not translate host name "postgres.railway.internal" to address: No such host is known.

"railway shell" then "psql" gives,

psql: error: could not translate host name "postgres.railway.internal" to address: Name or service not known

Connecting to it using the public url doesn't work either...

psql postgresql://postgres:CzCOhibytgDwvOIioJGaNXCsSiCyBVTy@autorack.proxy.rlwy.net:5432/railway

psql: error: connection to server at "autorack.proxy.rlwy.net" (35.213.179.112), port 5432 failed: Connection timed out (0x0000274C/10060)

Is the server running on that host and accepting TCP/IP connections?

What's the problem. Is there something I have not yet set up? My settings.py file has,

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ["PGDATABASE"],
        'USER': os.environ["PGUSER"],
        'PASSWORD': os.environ["PGPASSWORD"],
        'HOST': os.environ["PGHOST"],
        'PORT': os.environ["PGPORT"],
    }
}

which I believe to be correct. My environment variables on the server correspond to those on the railway database. Everything works locally, just not on railway via the CLI.

Thanks so much for any help!!

0 Replies

Django PostgreSQL template database not working - Railway Help Station