Create a Database in Django
In the previous chapter, we briefly explained most parts of the Django basic architecture – urls.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.
- Create Django Models by updating the models.py file
- Create a migration file by running the
makemigration
command - 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.