[Solved]-Error when reverting an auto-generated migration for renaming a table in Django


You can override Migration.unapply so it uses a different set of operations.

class MyMigration(Migration):
    operations = [
        ... your operations ...
    reverse_operations = [
        ... your fixed reverse operations ...
    def unapply(self, project_state, schema_editor, collect_sql=False):
        self.operations = self.reverse_operations
        return super(MyMigration, self).unapply(..)

I have not tested this but it should give you an idea. Oh and you might need to reverse the list of reverse migrations because Django will be expecting it to be the list of forward migrations so traverse them in reverse.


Leave a comment