Django worked perfectly locally, but had errors in production (I was using the same postgres DB and configuration).
Django server, hosted on Railway gave me this:

Newtorking tab in Postgres settings on Railway:
Settings: (WORKED PERFECTLY ON A LOCAL MACHINE WITH THIS IN-PROD DATABASE AND SAVED DATA)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', //tried django.db.backends.postgresql, not working
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('DB_HOST'),
'PORT': os.getenv('DB_PORT'),
}
}
DATABASE_URL = os.getenv('DATABASE_URL')
.env: (everything in {{}} is a variable)
DATABASE_PRIVATE_URL={{DATABASE_PRIVATE_URL}} //not using this
DATABASE_URL={{DATABASE_URL}}
DB_HOST=viaduct.proxy.rlwy.net
DB_NAME=railway
DB_PASSWORD={{DB_PASSWORD}}
DB_PORT=19232
DB_USER=postgres
SECRET_KEY={{SECRET_KEY}}
So I did:
<myname>@my-MBP django_project % psql -h localhost -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-----------------+----------+---------+-------+-----------------------
postgres | <myname> | UTF8 | C | C |
template0 | <myname> | UTF8 | C | C | =c/<myname> +
| | | | | <myname>=CTc/<myname>
template1 | <myname> | UTF8 | C | C | =c/<myname> +
| | | | | <myname>=CTc/<myname>
(3 rows)
<myname>@my-MBP django_project % psql -h localhost -d postgres
psql (14.11 (Homebrew))
Type "help" for help.
postgres=#
And got (On Railway):
Django server:
Postgres Database:

Doing this locally gives me the same error that was given in production
<myname>@my-MBP django_project % psql -h /var/run/postgresql -d postgres
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Again, before I ran psql -h localhost -d postgres everything was working perfectly on a LOCAL Django server. But in production, with the same configuration and database (hosted) it was not working.
