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.
makemigrations are run through the following command
Python manage.py makemigrations
If the above commands says no changes detected, You can also do it for individual apps.
For example if you have 10 apps named a, b, c, d, e, f, g, h, i, j. You can run makemigrations individually for these apps.
Python manage.py makemigrations a
Python manage.py makemigrations b
Python manage.py makemigrations c
and so on.
Django app model makemigrations
makemigrations basically generates the SQL commands for preinstalled apps (which can be viewed in installed apps in settings.py) and your newly created apps’ model which you add in installed apps. It does not execute those commands in your database file. So tables are not created after makemigrations.
After applying makemigrations you can see those SQL commands with sqlmigrate which shows all the SQL commands which have been generated by makemigrations.
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.
- Django Basic App Model - Makemigrations and Migrate
- Python | Django News App
- Weather app using Django | Python
- How to Create an App in Django ?
- Dockerizing a simple Django app
- Django manage.py migrate command | Python
- Add the slug field inside Django Model
- Django model data types and fields list
- Render Model in Django Admin Interface
- Deploy Python Flask App on Heroku
- Python | Creating a Simple Drawing App in kivy
- Create a Weather app using Flask | Python
- Todo list app using Flask | Python
- Kivy - Python Framework for Mobile App development
- Image Viewer App in Python using Tkinter
- Python | User groups with Custom permissions in Django
- Python | Django Admin Interface
- Python | Form validation using django
- Python | Django-allauth setup and Configuration
- Python Django | Google authentication and Fetching mails from scratch
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.