Moving a database from one state to another is called a migration. The Django framework can manage our migrations by creating a migration file based on the existing Django Data Models of the application.

This is done with python manage.py makemigrations <app>. Once a migration file has been generated we can migrate the actual database with the migrate command: python manage.py migrate

This will create a migration file for a specific app in a Django project. For example, given the following model…

Django  Data Models

… will create the following file:

# Generated by Django 5.1.3 on 2024-11-30 00:18
 
from django.db import migrations, models
 
 
class Migration(migrations.Migration):
 
    initial = True
 
    dependencies = []
 
    operations = [
        migrations.CreateModel(
            name="Blog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("title", models.CharField(max_length=200)),
                ("description", models.TextField()),
                ("date_added", models.DateTimeField(auto_now_add=True)),
            ],
        ),
    ]