This website collects cookies to deliver better user experience
Django Migrations
Django Migrations
Introduction
In the last episode, we talked about Django Architecture and settings.py file. In this episode, we'll discuss Django Migrations.
Django Migrations
Migrations are used to update the changes (to add a new field, change the name of a field, etc.) we made in the model to the database.
Django creates migration files (a Python file) inside the migration folder for each model to create the table schema, and then each table is mapped to the respective migration files. Django also keeps track of the status of migration files whether they are successfully migrated to the database.
To perform migration-related tasks, we can use these commands.
makemigrations
python manage.py makemigrations
This is used to create migrations files in the migrations folder based on the changes we have done to the Model.
migrate
python manage.py migrate
Based on the migrations file, this command will populate the database schema.
showmigrations
python manage.py showmigrations
This lists all the migrations and their status. If the change is updated in the database, the status will be shown as [X] followed by the migration name.
For example: