[Django] #36721: Template for data migrations?

3 views
Skip to first unread message

Django

unread,
Nov 10, 2025, 4:28:51 AM (2 days ago) Nov 10
to django-...@googlegroups.com
#36721: Template for data migrations?
----------------------------------+---------------------------------------
Reporter: Willem Van Onsem | Type: New feature
Status: new | Component: Migrations
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+---------------------------------------
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).
--
Ticket URL: <https://code.djangoproject.com/ticket/36721>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 10, 2025, 9:40:11 AM (2 days ago) Nov 10
to django-...@googlegroups.com
#36721: Template for data migrations?
----------------------------------+--------------------------------------
Reporter: Willem Van Onsem | Owner: (none)
Type: New feature | Status: closed
Component: Migrations | Version: 5.2
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* resolution: => duplicate
* status: new => closed

Comment:

Duplicate of #29515.
--
Ticket URL: <https://code.djangoproject.com/ticket/36721#comment:1>

Django

unread,
Nov 11, 2025, 2:50:40 AM (yesterday) Nov 11
to django-...@googlegroups.com
#36721: Template for data migrations?
----------------------------------+--------------------------------------
Reporter: Willem Van Onsem | Owner: (none)
Type: New feature | Status: closed
Component: Migrations | Version: 5.2
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Comment (by David Sanders):

Hi Willem,

Just wanted to point out there is a new area for requesting features in
Django: https://github.com/django/new-features
--
Ticket URL: <https://code.djangoproject.com/ticket/36721#comment:2>
Reply all
Reply to author
Forward
0 new messages