Trouble connecting Django to PostgreSQL database
Hello,
I am very much a new developer trying to deploy a Django app with PostgreSQL. After reading the docs, it seemed to me that I should do the following:
* Provision a PostgreSQL database (which I have done, with Project ID: b90272c3-dbc8-4122-b259-9d4f79d6642d)
* Connect it to my local Django project (which has been shown to work with my local PostgreSQL).
* Eventually, I would then set these environment variables with a .env and it should just work after deploying. I'm sort of following this tutorial: https://kowe.io/guide/deploy-django-on-railway-postgresql
However, I'm having trouble connecting my Railway provisioned database to my local Django project. When I try to run python3 manage.py migrate, the command just hangs for a very long time with no visible errors. I would really appreciate any help or direction.
Deploy Django on Railway - PostgreSQL - by clintonmatics - Kowe.
This tutorial is about deploying your Django web application to Railway, this time with a PostgreSQL database.
137 Replies
Project ID:
b90272c3-dbc8-4122-b259-9d4f79d6642d
is your postgres database in the same project as your django service?
Hi Brody, thanks for answering. I think that's maybe what I'm trying to set up. I haven't hosted my Django project anywhere, it's just on my local machine. I am hoping to have it be hosted by Railway and use the Postgres DB, if that makes sense. I thought I would connect my local django project to the Railway Postgres DB first and then continue on. Does that make sense? Maybe I'm not expressing myself well of I have a misunderstanding in how this should work.
yeah it makes sense, you only have the database on railway right now
show me the database thing in your settings.py please
Ah, I see...I think I can see how I can make a Django deployment that includes an already linked Postgres database now...
In any case, this is my database setup in settings.py:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.environ.get("PGDATABASE"),
"USER": os.environ.get("PGUSER"),
"PASSWORD": os.environ.get("PGPASSWORD"),
"HOST": os.environ.get("PGHOST"),
"PORT": os.environ.get("PORT"),
}
}
And in my .env file, I have the actual values, copied over from the Variables section of the database
Thank you so much for your help, by the way! I really appreciate it
lets try to do this in a way that doesnt involve putting the login to your database in a plaintext file
in the same project as your postgres database, add an empty service
OK, thank you. I added it
screenshot please
![No description](https://cdn.answeroverflow.com/1222937763737768037/image.png)
give it a better name haha
ok, I just went for the default
Will this empty service host the environment files? Or would it be the django project? What makes sense as a name?
this empty service for now will hold the variables, and it will also eventually be where you deploy your app to
so lets see a new screenshot after the name change
Ok, I see
Here you go
![No description](https://cdn.answeroverflow.com/1222938623020630056/image.png)
for the sake of simplicity, just name it "bibblio"
no need for complex names here