How to use PostgreSQL Database in Django? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 11 Likes Like Report See More This article revolves around how can you change your default Django SQLite-server to PostgreSQL. PostgreSQL and SQLite are the most widely used RDBMS relational database management systems. They are both open-source and free. There are some major differences that you should be consider when you are choosing a database for your applications. Also checkout - Difference between SQLite and PostgreSQL Setting up PostgreSQL in Django First create a virtual env so to do that first install virtualenv using this command pip install virtualenv then we will create a virtualenv named gfg using virtualenv gfg to enter in the virtual environment create use now we will install Django here so I am using Django 2.2 pip install django==2.2.* To get Python working with Postgres, you will need to install the “psycopg2” module. pip install psycopg2 now lets create a django project named geeks django-admin startproject geeks to check your django is running smoothly python manage.py runserver Now, go to the below link and download and set up PostgreSQL. create a database name gfg in your Postgres server. Now its time to switch from SQLite to PostgreSQL. Folder structure - open the settings.py file now change database settings with this template code DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': ‘<database_name>’, 'USER': '<database_username>', 'PASSWORD': '<password>', 'HOST': '<database_hostname_or_ip>', 'PORT': '<database_port>', } } Run these commands python manage.py makemigrations python manage.py migrate now lets create the default superuser: python manage.py createsuperuser now again run your server with python manage.py runserver go to this route and add the credential you did while creating superuser http://127.0.0.1:8000/admin/ and if you are successfully able to log in, you have successfully switched to PostgreSQL Create Quiz Comment J jagritacharya2019 Follow 11 Improve J jagritacharya2019 Follow 11 Improve Article Tags : PostgreSQL Python Django Explore BasicsWhat is PostgreSQL - Introduction2 min readInstall PostgreSQL on Windows2 min readInstall PostgreSQL on Mac3 min readDatabase OperationsPostgreSQL - Create Database5 min readPostgreSQL - Loading a Database3 min readPostgreSQL ALTER DATABASE3 min readPostgreSQL - Rename Database4 min readPostgreSQL - Show Databases3 min readData TypesPostgreSQL - Data Types5 min readPostgreSQL - Boolean Data Type4 min readPostgreSQL - CHAR Data Type5 min readPostgreSQL - VARCHAR Data Type3 min readPostgreSQL - NUMERIC Data Type5 min readPostgreSQL - Date Data Type4 min readPostgreSQL - TIME Data Type4 min readPostgreSQL - JSON Data Type4 min readPostgreSQL - CREATE DOMAIN3 min readQuerying TablesPostgreSQL - SELECT3 min readPostgreSQL - ORDER BY clause2 min readPostgreSQL - WHERE clause6 min readPostgreSQL FETCH Clause4 min readPostgreSQL - IN operator4 min readPostgreSQL - HAVING clause4 min readPostgreSQL - GROUP BY clause4 min readPostgreSQL - LIKE operator5 min readPostgreSQL - BETWEEN Operator3 min readTable OperationsPostgreSQL - CREATE TABLE5 min readPostgreSQL - SELECT INTO4 min readPostgreSQL - CREATE SEQUENCE4 min readPostgreSQL - ALTER TABLE6 min readPostgreSQL - ADD COLUMN4 min readPostgreSQL - DROP COLUMN2 min readPostgreSQL - Rename Table2 min readPostgreSQL - DROP TABLE5 min readPostgreSQL - TRUNCATE TABLE4 min readPostgreSQL - Copy a Table3 min readPostgreSQL - Comparing Tables3 min readPostgreSQL - Show Tables4 min readModifying DataPostgreSQL - INSERT4 min readPostgreSQL - Insert Multiple Values in Various Rows3 min readPostgreSQL UPDATE Statement5 min readPostgreSQL - DELETE4 min readPostgreSQL - Upsert4 min readConditionalsPostgreSQL - CASE3 min readPostgreSQL COALESCE5 min readPostgreSQL - NULLIF() Function4 min readPostgreSQL - CAST3 min readControl FlowPostgreSQL - IF Statement5 min readPostgreSQL - CASE Statement4 min readPostgreSQL - Loop Statement3 min readPostgreSQL - While Loops4 min readPostgreSQL - Exit Statement3 min readPostgreSQL - Continue3 min readTransactions & ConstraintsPostgreSQL - Transactions4 min readPostgreSQL - COMMIT4 min readPostgreSQL - Primary Key4 min readPostgreSQL - Foreign Key5 min readPostgreSQL - CHECK Constraint2 min readPostgreSQL - UNIQUE Constraint3 min readPostgreSQL - NOT NULL Constraint3 min readJOINS & SchemasPostgreSQL - Joins5 min readPostgreSQL - LEFT JOIN5 min readPostgreSQL - INNER JOIN2 min readPostgreSQL - FULL OUTER JOIN4 min readPostgreSQL - SELF JOIN4 min readPostgreSQL - Schema5 min readPostgreSQL - CREATE SCHEMA5 min readPostgreSQL - DROP SCHEMA4 min readPostgreSQL - ALTER SCHEMA3 min read Like