DEV Community

Cover image for Django: makemigrations and migrate
Banji
Banji

Posted on

Django: makemigrations and migrate

In this post, I'm trying to explain what makemigrations and migrate commands can do in Django.

We have these 2 commands in Django to create SQL commands:

Alt Text

Now let's see what exactly they are doing with our database.

  1. First we create a new model class in models.py

Alt Text

Then in command-line:
Alt Text

makemigrate: What will happen after this command?
It will generate the SQL command to create the table corresponding to each class you made in the models.py file.

The corresponding SQL command after creating your class models in models.py and using makemigrations will be

Alt Text

and finally, we run this command:
Alt Text
migrate: What will happen after this command?
It will create the table in the database using the commands which have been generated by makemigrations.

Top comments (2)

Collapse
 
amirdarx profile image
amir

good job bro

Collapse
 
banji220 profile image
Banji

Homie G