Deployed my Django application on Railway, getting a server error 500 when accessing my admin, etc.

Anyone who has ever faced the similar issues, what are the usual causes of this? I am getting the server error 500 whenever I try to access my admin or other valid URLs. Note that: I haven't configured any databases yet.

Solved

15 Replies

41c59dc8-07dc-421d-8a27-e17cf0d0bcd7


brody
EMPLOYEE

a year ago

i'd recommend setting debug to true so that django will tell you what is wrong


okay will try


yep getting the error that I expected:
OperationalError at /adminzurro/login/
connection to server at "127.0.0.1", port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
Request Method: POST
Request URL: http://azurrodjangoprod-production.up.railway.app/adminzurro/login/?next=/adminzurro/
Django Version: 5.0.7
Exception Type: OperationalError
Exception Value:
connection to server at "127.0.0.1", port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
Exception Location: /opt/venv/lib/python3.12/site-packages/psycopg2/init.py, line 122, in connect
Raised during: django.contrib.admin.sites.login
Python Executable: /opt/venv/bin/python

This is very likely because of the database config, right?


brody
EMPLOYEE

a year ago

yes, 5432 is Postgres, likely means you are not using the proper environment variables in code to connect to the database on railway


I have a question tho, I am rn using my local PG database in the deployed code. I was using Heroku for my last deploy and for price concerns I shifted to railway.
After creating a new postgres database in railway, will I be able to migrate my heroku db here?


brody
EMPLOYEE

a year ago

yep, just pgdump the old database and pgrestore to the railway database, there's many many online guides for that!


can you give me any such docs that I can refer to?


brody
EMPLOYEE

a year ago

sorry, I don't have any on hand, but they'd be a quick web search away!


cool!


hi can you check out this error that I am getting while connecting my railway postgres db to my local django project which I will deploy later:

RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not translate host name "postgres.railway.internal" to address: No such host is known.


this is what I am using in the settings.py code:

Database settings

from decouple import config

DATABASES = {
'default': djdatabaseurl.parse(config('DATABASE_URL'))
}


oh nvm, got it done. Was not using the public url. Thanks btw, my entire django code is deployed now along with the db.


brody
EMPLOYEE

a year ago

awesome glad to hear that?


brody
EMPLOYEE

a year ago

!s


Status changed to Solved brody about 1 year ago


Loading...