I was working on A Django project and it worked perfectly fine on the local server, especially when it came to form handling like user signup, login even admin login. But after I deployed it to Railway, first i got the error of csrf token, so it could not load any forms, which i solved with
CSRF_TRUSTED_ORIGINS = ['https://domain_name.com']
which worked and now the forms load up but when after I fill in the details, the admin login, user sign up and login pages, and I hit the save but it throws back and error "SERVER ERROR(500)" I am really confused on what to do... someone please point me in the right direction please Railway also throws back the following logs when i try to access the website features
[2023-08-29 08:22:35 +0000] [1] [INFO] Starting gunicorn 21.2.0
[2023-08-29 08:22:35 +0000] [1] [INFO] Listening at: http://0.0.0.0:7083 (1)
[2023-08-29 08:22:35 +0000] [1] [INFO] Using worker: sync
[2023-08-29 08:22:35 +0000] [9] [INFO] Booting worker with pid: 9
Internal Server Error: /student/studentsignup
Traceback (most recent call last):
File "/opt/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
self.connect()
File "/opt/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 270, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
connection = self.Database.connect(**conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.OperationalError: connection to server at "containers-us-west-49.railway.app" (34.127.80.91), port 7083 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/student/views.py", line 34, in student_signup_view
if userForm.is_valid() and studentForm.is_valid():
^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/forms/forms.py", line 201, in is_valid
return self.is_bound and not self.errors
^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/forms/forms.py", line 196, in errors
self.full_clean()
File "/opt/venv/lib/python3.11/site-packages/django/forms/forms.py", line 435, in full_clean
self._post_clean()
File "/opt/venv/lib/python3.11/site-packages/django/forms/models.py", line 492, in _post_clean
self.validate_unique()
File "/opt/venv/lib/python3.11/site-packages/django/forms/models.py", line 501, in validate_unique
self.instance.validate_unique(exclude=exclude)
File "/opt/venv/lib/python3.11/site-packages/django/db/models/base.py", line 1229, in validate_unique
errors = self._perform_unique_checks(unique_checks)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/db/models/base.py", line 1339, in _perform_unique_checks
if qs.exists():
^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/db/models/query.py", line 1241, in exists
return self.query.has_results(using=self.db)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/db/models/sql/query.py", line 598, in has_results
return compiler.has_results()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1530, in has_results
return bool(self.execute_sql(SINGLE))
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1560, in execute_sql```
Please Note the following:
1. I have not installed the PostgreSql on my machine, It was running smoothly during production process when I connected Railway postgres to my project.
2. I know momentarily switched my "DEBUG" to true and the following error exception was thrown back.
connection to server at "containers-us-west-49.railway.app" (34.127.80.91), port 7083 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?``` I hope this is helpful? What am I missing here?
let me share my requirements.txt just incase its needed to help solve this issue
asgiref==3.7.2
certifi==2023.7.22
charset-normalizer==3.2.0
crispy-bootstrap4==2022.1
Django==4.2.4
django-cors-headers==4.2.0
django-crispy-bootstrap==0.1.1.1
django-crispy-forms==2.0
django-extensions==3.2.3
django-widget-tweaks==1.4.12
gunicorn==21.2.0
idna==3.4
packaging==23.1
Pillow==10.0.0
psycopg2==2.9.7
python-decouple==3.8
requests==2.31.0
sqlparse==0.4.4
tzdata==2023.3
urllib3==2.0.4
whitenoise==6.5.0