...

/

Database and Media Files Setup

Database and Media Files Setup

Learn how to set up a database along with static and media files in your Django web app.

SQLite 3 database setup


The default database used by Django is the SQLite3 database. The following piece of code is generated whenever we set up a new Django web app.

SQLite
Press + to interact
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
...

PostgreSQL database setup


In this course, we’ll be using the PostgreSQL database. To use the PostgreSQL database, we need to modify the DATABASES field in the settings.py as follows:

PostgreSQL
Press + to interact
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '<database_name>',
'USER': '<database_username>',
'PASSWORD': '<database_password>',
'HOST': 'localhost',
'PORT': '<port>',
}
}
...

ENGINE

Refers to the database component used to perform CRUD (Create, Read, Update, Delete) operations on the database data.

NAME

Refers to the name of the database.

...