#23347: Add --dry-run to migrate
-------------------------------+--------------------------------------
     Reporter:  Richard Eames  |                    Owner:  nobody
         Type:  New feature    |                   Status:  closed
    Component:  Migrations     |                  Version:  1.7-rc-3
     Severity:  Normal         |               Resolution:  needsinfo
     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 Michael):

 The plan option does not help me, it just says `Raw Python operation` for
 my custom migration.

 I just added a error at the end of the migration, so that it rolls back,
 now can run it as many times as desired, then remove the error when
 confident:

 {{{
 from django.db import migrations


 def forwards_func(apps, schema_editor):
     Meeting = apps.get_model("meetings", "Meeting")
     db_alias = schema_editor.connection.alias
     for meeting in Meeting.objects.using(db_alias).all():
         if meeting.meeting_utc is None:
             print(meeting.meeting_date, meeting.meeting_time)
     raise ValueError("Don't commit!")  # <----------------

 class Migration(migrations.Migration):
     dependencies = [
         ('meetings', '0004_meeting_meeting_utc_meeting_time_is_null'),
     ]

     operations = [
         migrations.RunPython(forwards_func),
     ]

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23347#comment:9>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/010701839e5cbe0c-54583b9a-6de2-4645-94a4-d624aedfb88e-000000%40eu-central-1.amazonses.com.

Reply via email to