-
Notifications
You must be signed in to change notification settings - Fork 233
Database Setup
Horilla edited this page May 24, 2023
·
2 revisions
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.
To set up a postgresql database for the project, first you have to install the PostgreSQL and its python package psycopg2 .
Replace <database_name>, <database_user>, <database_password>, <database_host>, and <database_port> with your PostgreSQL database settings.
For more details: Django PostgreSQL Database
To configure a MySQL database in Django, follow these steps:
Replace <database_name>, <database_user>, <database_password>, <database_host>, and <database_port> with your MySQL database settings.
For more details: Django MySQL Database
To configure a MariaDB database with Django, you can follow the same steps used for MySQL database configuration as shown above.
This will create a SQLite database in your project directory named db.sqlite3.
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.
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
For more details: Django Oracle Database
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.
- 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': '',
}
}
- Run migrations to create the necessary database tables.
python manage.py makemigrations
python manage.py migrate
- 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': '',
}
}
- Run migrations to create the necessary database tables.
python manage.py makemigrations
python manage.py migrate
For more details: Django MariaDB Database
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',
}
}
- Run migrations to create the necessary database tables.
python manage.py makemigrations
python manage.py migrate
For more details: Django SQLite Database
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:
- In the project settings file (settings.py), add the following database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
python manage.py makemigrations
python manage.py migrate
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