According to documentation, Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations when to run them, and the common problems you might run into.
migrate is run through the following command for a Django project.
Python manage.py migrate
Django python manage.py migrate command
migrate executes those SQL commands in the database file. So after executing migrate all the tables of your installed apps are created in your database file.
You can confirm this by installing SQLite browser and opening db.sqlite3 you can see all the tables appears in the database file after executing migrate command.
For example, if we make a model class-
The corresponding sql command after using makemigrations will be
CREATE TABLE myapp_person ( "id" serial NOT NULL PRIMARY KEY, "first_name" varchar(30) NOT NULL, "last_name" varchar(30) NOT NULL );
and using above command, table will be created in the database when we use migrate.
Migrate command is covered in next article.
and now form terminal running following command will create table for this model in your database
Python manage.py migrate
Now if we check our database, a table with name geeks_geeksmodel is created,
- Django Basic App Model - Makemigrations and Migrate
- Django App Model - Python manage.py makemigrations command
- Migrate PyQt5 app to PySide2
- Django URL patterns | Python
- Views In Django | Python
- Python | Django News App
- Django Migrations | Python
- Weather app using Django | Python
- Python | Sessions framework using django
- Python | Django Admin Interface
- Python | Form validation using django
- Complete Django History | Python
- Intermediate fields in Django | Python
- Python | ToDo webapp using Django
- Python | Uploading images in Django
- Python | Django-allauth setup and Configuration
- Python | Relational fields in Django models
- Python | Extending and customizing django-allauth
- Django Sign Up and login with confirmation Email | Python
- Python | User groups with Custom permissions in Django
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.