Opened 7 years ago

Closed 7 years ago

#29515 closed New feature (wontfix)

put sample code in empty migrations

Reported by: Chris Curvey Owned by: nobody
Component: Migrations Version: 2.0
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 (last modified by Tim Graham)

SHORT VERSION: put sample code into the generated file when creating an "empty" migration, like this:

#def combine_names(apps, schema_editor):
#    # We can't import the Person model directly as it may be a newer
#    # version than this migration expects. We use the historical version.
#    Person = apps.get_model('yourappname', 'Person')
#    for person in Person.objects.all():
#        person.name = '%s %s' % (person.first_name, person.last_name)
#        person.save()

    operations = [
        #migrations.RunPython(combine_names),
    ]

LONG VERSION/JUSTIFICATION:

Every time I create a data migration (python manage.py makemigrations foo --empty), I have to do a web search to remember what the parameters are to the function I want to call (apps, schema_editor), and how to use those parameters, and how to get the code to actually run (migrations.RunPython).

It would be really nice to have that sample code just put into the empty migration so that it is there as an example.

Change History (1)

comment:1 by Tim Graham, 7 years ago

Component: UncategorizedMigrations
Description: modified (diff)
Resolution: wontfix
Status: newclosed

I don't think there would be consensus to do this (but the place to try to get consensus is the DevelopersMailingList). For one thing, empty migrations aren't necessarily data migrations.

There have been similar discussions regarding making startapp generate more than it currently does.

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