Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#22445 closed Bug (fixed)

Doc on reversible data migrations needed

Reported by: Karen Tracey Owned by: Tim Graham
Component: Documentation Version: 1.7-beta-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If I create a data migration, run it, then try to migrate back to before it, I get:

  Unapplying m3app.0003_auto_20140415_1022...Traceback (most recent call last):
  File "./", line 10, in <module>
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/", line 427, in execute_from_command_line
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/", line 419, in execute
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/commands/", line 145, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/", line 62, in migrate
    self.unapply_migration(migration, fake=fake)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/", line 114, in unapply_migration
    migration.unapply(project_state, schema_editor)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/", line 121, in unapply
    raise Migration.IrreversibleError("Operation %s in %s is not reversible" % (operation, self))
django.db.migrations.migration.IrreversibleError: Operation <RunPython <function load_initial_data at 0x7f7af2424050>> in m3app.0003_auto_20140415_1022 is not reversible

I cannot find any documentation on how to create a reversible data migration. I'm used to doing this with South, I assume there is some way to do this in the new migrations framework? We need some doc on how to do it...or if this is not just a missing doc issue then this needs to be re-classified as a migrations code issue...

Change History (6)

comment:1 Changed 4 years ago by Karen Tracey

Peeking at the code reveals RunPython can be handed a 2nd callable to do the "reverse" operation. So I think this doc:

specifically needs to be updated to include mention of that, at a minimum.

comment:2 Changed 4 years ago by Simon Charette

Triage Stage: UnreviewedAccepted

comment:3 Changed 4 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:4 Changed 4 years ago by Tim Graham

It's covered in the RunPython reference, but I will add a couple sentences to the topic guide.

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 1ce759b69f641fd780790630c79559fc68a2d923:

Fixed #22445 -- Added how to perform a reverse data migration to topic guide.

Thanks Karen Tracey for the report.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

In 23f3c53aff54b7f298f29e97042d00dbd9379d00:

[1.7.x] Fixed #22445 -- Added how to perform a reverse data migration to topic guide.

Thanks Karen Tracey for the report.

Backport of 1ce759b69f from master

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