Database URL different and not working

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 ensure_connection 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.get_new_connection(conn_params) 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 get_new_connection connection = self.Database.connect(conn_params) File "/opt/venv/lib/python3.10/site-packages/psycopg2/init.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **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: db_url = os.environ["DATABASE_URL"] DATABASES = {"default": dj_database_url.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?
Solution:
switch to v2
Jump to solution
13 Replies
Percy
Percy3mo ago
Project ID: dc4f0585-2e8b-4706-bd9a-ff136257ec90
Lewis981
Lewis981OP3mo ago
dc4f0585-2e8b-4706-bd9a-ff136257ec90
Brody
Brody3mo 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
Lewis981
Lewis981OP3mo 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.
Brody
Brody3mo 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?
Lewis981
Lewis981OP3mo 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
Brody
Brody3mo ago
is your Django service on the V2 runtime? check your service settings
Lewis981
Lewis981OP3mo ago
Where would I find that?
Brody
Brody3mo ago
service settings
Lewis981
Lewis981OP3mo ago
Its on Legacy
Solution
Brody
Brody3mo ago
switch to v2
Lewis981
Lewis981OP3mo ago
I'll give it a shot That did it! Thanks.
Brody
Brody3mo ago
no problem!
Want results from more Discord servers?
Add your server