#29515: put sample code in empty migrations
------------------------------+--------------------------------------
     Reporter:  Chris Curvey  |                    Owner:  nobody
         Type:  New feature   |                   Status:  closed
    Component:  Migrations    |                  Version:  2.0
     Severity:  Normal        |               Resolution:  wontfix
     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 Tim Graham):

 * status:  new => closed
 * component:  Uncategorized => Migrations
 * resolution:   => wontfix


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

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

     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.

--

Comment:

 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29515#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.58beba0ba625694651620c65fd6bca96%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to