Database URL different and not working

lewisfletcher
PRO

10 months 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?

0 Replies

lewisfletcher
PRO

10 months ago

dc4f0585-2e8b-4706-bd9a-ff136257ec90


10 months 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
PRO

10 months 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.


10 months 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
PRO

10 months 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


10 months ago

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


lewisfletcher
PRO

10 months ago

Where would I find that?


10 months ago

service settings


lewisfletcher
PRO

10 months ago

Its on Legacy


10 months ago

switch to v2


lewisfletcher
PRO

10 months ago

I'll give it a shot


lewisfletcher
PRO

10 months ago

That did it! Thanks.


10 months ago

no problem!


Database URL different and not working - Railway Help Station