- Create Database
- Configure in settings.py
- Run migrations
In this tutorial we will start with a blank django project and create a new postgress databse. This process is very simple
First lets create our NEW postgress database. We will call our database “pgadminstudy”.
No lets configure in settings.py of our django project. In settings.py we will need to update our DATABASE to reflect our connection to posgress instead of the default sqlite.
We will update “Engine” and “Name” to reflece our postgress engine name “django.db.backends.postgresql” and the name shoud be the name we gave our database, in our case “pgadminstudy”
Then we will need to add a “USER“, “PASSWORD”, “HOST” and “PORT“.
IF you are working with a local postgress database your “USERNAME” will be “postgres”
“PASSWORD” is the password you created for your local pgadmin account.
“HOST” is simply “localhost” and “PORT” is “5432”
This information can be found when you open up pgadmin then right click on your server and select properties. All this info should be under the “Connection” Tab.
Here is hat DATABASE should look like now in settings.py
No before we run a migration i created a simple model that i want to be added to our databse.
No in our command prompt we can run “python manage.py makemigrations” and “python manage.py migrate”
No when we go into pgadmin and select our server –> database we can go to “schemas” –> “Public” — “Tables” and see our new table. Thats it! You django app should run just like it did with sqllite.