Opened 8 years ago

Closed 8 years ago

#27525 closed New feature (wontfix)

Revert to previous migration automatically after failure when using MySQL backend

Reported by: Sandy Agafonoff Owned by: nobody
Component: Migrations Version: 1.10
Severity: Normal Keywords: migrations, mysql, revert
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Owing to the fact MySQL does not support transactional DDL, would it be possible to automatically migrate to the previous migration, rather than leave the database in an inconsistent state?

Obviously, not all statements in a migration can be reversed, and, reverting to the previous migration is currently the developers decision, however in a cloud based CI/CD, automatic deployment based environment, allowing this to be run without human intervention would be a plus.

Possibly a flag on the migrate command like --fail-revert, or possibly a field in the migration class would be best, so I can decide on a per-migration basis the behaviour I would intend.

I understand this is going to be a niche request, however, I would like to open a discussion to see if there is some merit here.

Change History (2)

comment:1 by Shai Berger, 8 years ago

Type: Cleanup/optimizationNew feature


Thanks for this suggestion. Three points come to mind:

At a normal "meta" level: If indeed this is a niche request, perhaps it can be fulfilled by means of a 3rd-party app; apps can override and enhance Django's management commands. So you can write your own "migrate" command, or a "migrate_and_on_error_back" command, that will do just that.

At the subject matter level: When a migration fails, it usually means something unexpected happened. In these circumstances, it is more prudent to stop and let a human examine the situation, rather than attempt automatic fixes which are, in essence, based on the assumptions that were broken. For this reason, I tend to think it isn't a good idea to put such an option into Django -- adding it would endorse a practice which, I suspect, is more likely to cause harm than good in the general case.

At the highest "meta" level: If you want to open a discussion, it is better to do so on the DevelopersMailingList, where many more people will see it.

comment:2 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

I agree with Shai. If you have an implementation to share, that would certainly help better evaluate the idea. We can reopen if the ticket if there's consensus on the mailing list to proceed.

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