2 months ago
Please I need assistance I want to connect all my Django projects database through private network but don't know how I tried I always keep my connection in a env file in my project
6 Replies
2 months ago
Hey there
You'll have to use the internal hostnames like postgres.railway.internal
in your .env
file for the database URL. Then make sure all your projects are linked on the same Railway private network. Then in Django’s settings, load the database URL from the env file and it should work.
2 months ago
The previous database variables should leave them please can you show an example of what to do
2 months ago
I configure with Db name,Db user, Db password, Db host, Db Port
2 months ago
Here's an example configuration for using private networking to connect to your database. Your environment variable and service names might be different. So please adjust as needed.PG__HOST="${{Postgres.PGPRIVATEHOST}}"
PG__USER="${{Postgres.PGUSER}}"
PG__PASSWORD="${{Postgres.PGPASSWORD}}"
PG__DBNAME="${{Postgres.PGDATABASE}}"
Attachments
2 months ago
Please be aware that private networking has some initialization lag, so your app might crash if you try to connect to your database immediately upon starting the app. If that happens you might want to add some delay on startup.
2 months ago
If you want to use an .env file instead of railway variables like the other person suggested, check the values of those variables in your database service and enter them directly.
Status changed to Solved brody • 2 months ago