Database URL different and not working
lewisfletcher
PROOP

2 years ago

I'm struggling to set up my Django project, it can't use the DATABSE_URL value the way it normally would. I get this error:

Traceback (most recent call last):
File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 275, in ensureconnection self.connect() File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, *kwargs) File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 256, in connect self.connection = self.getnewconnection(connparams)
File "/opt/venv/lib/python3.10/site-packages/django/utils/
asyncio.py", line 26, in inner
return func(
args, *kwargs) File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 277, in getnewconnection
connection = self.Database.connect(
*conn_params)
File "/opt/venv/lib/python3.10/site-packages/psycopg2/init.py", line 122, in connect
conn = _connect(dsn, connectionfactory=connectionfactory, **kwasync)
psycopg2.OperationalError: could not translate host name "postgres.railway.internal" to address: Name or service not known

I am using the following code to connect to the DB:

dburl = os.environ["DATABASEURL"]
DATABASES = {"default": djdatabaseurl.parse(db_url, engine='django.db.backends.postgresql')}

This works great in another project I've deployed. But when I investigate the DATABASE_URL value in that project, it's different. Rather than using "postgres.railway.internal" it uses "roundhouse.proxy.rlwy.net"

Is this a recent change to database config on railway side, or am I just doing something wrong?

13 Replies

lewisfletcher
PROOP

2 years ago

dc4f0585-2e8b-4706-bd9a-ff136257ec90


2 years ago

yes, but default railway will use the private network for the database URL, if you need to access it locally you will need to use the public url


lewisfletcher
PROOP

2 years ago

Got it, so just use the public url value? If by locally you mean connecting to it remotely from my local instance, I'm not doing that. This occurs on the actual deploy. I may be misunderstanding what you mean by locally though.


2 years ago

ah okay, you never directly stated if this error was happening on railway, or locally so I took a guess based on how most people encounter this error.

is the Postgres database in the same project as the Django service?


lewisfletcher
PROOP

2 years ago

Sorry for the lack of clarity. Yes, the postgres DB is in the same project. I added the variable by using the reference function


2 years ago

is your Django service on the V2 runtime? check your service settings


lewisfletcher
PROOP

2 years ago

Where would I find that?


2 years ago

service settings


lewisfletcher
PROOP

2 years ago

Its on Legacy


2 years ago

switch to v2


lewisfletcher
PROOP

2 years ago

I'll give it a shot


lewisfletcher
PROOP

2 years ago

That did it! Thanks.


2 years ago

no problem!


Loading...