makemigration and migrate


At first

We've continued to summarize what Django we're studying. I write it down instead of a memoir to myself. Once I understand the basic functions, I am planning to make a household accounting app or something.

What is database migration?

Indicates the ability to automatically create and manage database definitions for use by applications.

As a premise、、、 table is not created in the DB, but by executing makemigrate and migrate, the table is created in the DB.


Create a migration file to create a table in the DB. As a role, create a new migration for the model written in the

python makemigrations

In the case of large-scale development, if all the DBs are changed at once, there is a possibility that a problem will occur, so if only the corresponding application is changed, execute as follows.

python makemigrations (アプリ名)


Use to apply migrations or cancel applications. Based on the created migration file, create a table in the DB.

python migrate

You have XX (numeric) unapplied migration(s).

If you try to get the server up and it says You have XX(数字) unapplied migration(s)., you can do makemigration and migrate to update the tables in the database to resolve it.

Further reading

I have referred to the following.

Django Migration Summary Getting Started with Python Using Django (Part 12) Migrating. Learn Notes: About Makemigrations and Migrate migration

Author by



Updated on April 21, 2021