Course Content
Django: First Dive
Django: First Dive
Migrations
The Python code is independent of the database.
To apply changes in our database, we need to create migrations.
Migration is the automated way of making changes to your database structure, ensuring that your database stays up to changes you make to your code.
When you create the Model class, you need to run the following commands in the Terminal:
makemigrations
The python manage.py makemigrations
command records the changes in the database and creates migrations.
Migrations are represented as Python files (.py
format).
These files contain scripts and data for migration and database structure changes.
Note
This is the process of the framework. Migrations work automatically. You do not need to touch these files. Only sometimes, there are moments when it is desirable to delete the migration and create a new one, but this is only a last resort.
migrate
To apply created migrations, you need to run another command in the Terminal.
The command python manage.py migrate
executes migrations scripts (.py
files) and sends queries to the database.
Note
When you move the Django to another device, you can run the
migrate
command only because the migrations are already saved in files.
Thanks for your feedback!