Django Database connections

By default Django support sqlite3 database if developer want to change database like MySQL or any other we can only change it through file and run without and stuff.

Firstly, open the file of your web-application/ project and there find this part.


    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': os.path.join(BASE_DIR, db.sqlite3'),



DATABASES is a pre-defined dictionary in Django Framework with the ‘default’ as an index having the value for the main database where all the data is to be stored.

There can be multiple databases as we need data backups too but there is only one default database, although we won’t be adding multiple databases now. Yet we will add all database connections code here which is helpful for database connections:

MySQL connection code:

Install xampp server and configure using this


    'default': {  

        'ENGINE': 'django.db.backends.mysql',  

        'NAME': 'dbName',  








Postgresql connection code:

Download, then install it under Python PATH

>pip install psycopg2

and then configure using


   default': {

      'ENGINE': 'django.db.backends.postgresql',

      'NAME': 'db_name', 'USER': 'db_user',

      'PASSWORD': 'db_user_password',

       'HOST': '',

       'PORT': 'db_port_number',