How to Connect and Configure Postgress SQL Database in Framework Django

HermantoXYZ
2 min readMar 21, 2024

--

2 The best Database for your bussines.

PostgreSQL and MySQL

PostgreSQL is an open-source object-relational database system that stands out for its reliability and performance. It’s ideal for businesses requiring advanced data management and supports complex data types and optimization.

Download here: https://postgresapp.com/downloads.html & https://www.postgresql.org/ftp/pgadmin/pgadmin4/v8.4/macos/

Configure your $PATH to use the included command line tools (optional):

sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp

To connect to a PostgreSQL server with Python, please first install the psycopg2 library:

pip install psycopg2

#INSTALL IN TERMINAL

Django

In your settings.py, add an entry to your DATABASES setting:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbpeduliki',
'USER': 'postgres',
'PASSWORD': '123',
'HOST': 'localhost', # Or your database host
'PORT': '5432', # Or your database port
}
}

Create Database:

CREATE DATABASE dbpeduliki;

Check Database:

\list
postgres=# psql -U dbpeduli
postgres-#

# OPEN DATABASE using terminal

Create an account superuser

Check database:

Succesfull..

--

--

No responses yet