Skip to content

Database Setup

Horilla edited this page May 24, 2023 · 2 revisions

Database Setup

By default an SQLite database will be set up for the project, in case you wish to change the database of your choice, please use the below reference to do the same.

Postgresql

To set up a postgresql database for the project, first you have to install the PostgreSQL and its python package psycopg2 .
  • Install the psycopg2 package using pip. This package is a PostgreSQL database adapter for Python.
pip install psycopg2
  • In the project settings file (horilla/settings.py), add the following database settings:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}
Replace <database_name>, <database_user>, <database_password>, <database_host>, and <database_port> with your PostgreSQL database settings.
  • Run migrations to create the necessary database tables.

python manage.py makemigrations
python manage.py migrate
For more details: Django PostgreSQL Database

MySQL

To configure a MySQL database in Django, follow these steps:
  • Install the mysqlclient package which will allow Django to interact with MySQL. You can install it using pip

pip install mysqlclient
  • In the project settings file (horilla/settings.py), add the following database settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}
Replace <database_name>, <database_user>, <database_password>, <database_host>, and <database_port> with your MySQL database settings.
  • Run migrations to create the necessary database tables.

python manage.py makemigrations
python manage.py migrate
For more details: Django MySQL Database

MariaDB

To configure a MariaDB database with Django, you can follow the same steps used for MySQL database configuration as shown above. 

For more details: Django MariaDB Database

SQLite

To configure a SQLite database with Django, you can follow these steps:
  • In the project settings file (settings.py), add the following database settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
This will create a SQLite database in your project directory named db.sqlite3.
  • Run migrations to create the necessary database tables.

python manage.py makemigrations
python manage.py migrate
Note that SQLite has some limitations compared to other databases, so you may need to consider these limitations if you have a large amount of data or a high level of concurrency in your application.

For more details: Django SQLite Database

OracleDB

To configure an Oracle database with Django, you can follow these steps:
  • Install the cx_Oracle package which will allow Django to interact with Oracle. You can install it using pip:
Pip install cx_Oracle
  • In the project settings file (settings.py), add the following database settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}
Replace <database_name>, <database_user>, <database_password>, <database_host>, and <database_port> with the appropriate values for your Oracle installation. Run migrations to create the necessary database tables
python manage.py makemigrations
python manage.py migrate
For more details: Django Oracle Database

 

Replace <database_name>, <database_user>, <database_password>, <database_host>, and <database_port> with the appropriate values for your Oracle installation.

  • Run migrations to create the necessary database tables.

python manage.py makemigrations
python manage.py migrate
Note that Oracle has some specific requirements for its database setup, so you may need to consult Oracle's documentation for more information on how to set up your database correctly.

For more details: Django Oracle Database