Opened 6 years ago

Last modified 6 years ago

#29515 closed New feature

put sample code in empty migrations — at Initial Version

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

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()

and then

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 (0)

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