Create a Database in Django

How to Create a Database for Your Django Project

In the previous chapter, we briefly explained most parts of the Django basic architectureurls.py as a URL dispatcher, views.py for providing fundamental logic to handle HTTP requests, and templates for converting views.py's output into HTML format.

models.py and database are the last critical parts of the Django basic architecture. To create a database in Django, models.py plays a critical role in providing database design information.

Key steps to create a database in Django

In Django, there are three steps to create a database.

  1. Create Django Models by updating the models.py file
  2. Create a migration file by running the makemigration command
  3. Create database tables by running the migrate command

In addition to these three steps, you may want to modify the admin.py file to reflect a newly created database on the Django admin page.

In the following sections, we'll explain the key steps in detail.


You can also learn this topic offline. Click AmazonKindle.

Django Introduction
Course Content