#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019a6d18ac6e-6de73650-4300-45e3-af3e-6bcb002929e6-000000%40eu-central-1.amazonses.com.

Reply via email to