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
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
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?
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
10 months ago
service settings
10 months ago
switch to v2
10 months ago
no problem!