#36721 new New feature

Template for data migrations?

Reported by: Willem Van Onsem Owned by:
Component: Migrations Version: 5.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When running:

manage.py makemigrations --empty app_name

we get a file that looks like:

# Generated by Django 5.2.4 on 2025-11-10 09:23

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ("app_name", "0123_other_migration"),
    ]

    operations = []

I find it a bit incovenient that each time, I have to remember how to add a RunPython migration: this is something that happens regularly, but probably not regularly enough to just remember it.

Is it an idea to make a template that looks like:

# Generated by Django 5.2.4 on 2025-11-10 09:23

from django.db import migrations


def forward(apps, schema_editor):
    MyModel = apps.get_model('app_name', 'MyModel')

class Migration(migrations.Migration):

    dependencies = [
        ("app_name", "0123_other_migration"),
    ]

    operations = [
        migrations.RunPython(forward)
    ]

This would increase productivity a bit, but I think it will also help users not to import models directly but use the historic models at the time of the migration (probably something that i not always done neatly). Furthermore the migration will by default fail (since no MyModel exists, and therefore prevents adding an empty migration to the chain).

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top