'Take a project_state representing all migrations prior to this one
and a schema_editor for a live database and apply the migration
in a reverse order.
The backwards migration process consists of two phases:
1. The intermediate states from right before the first until right
after the last operation inside this migration are preserved.
2. The operations are applied in reverse order using the states
recorded in step 1.'

def unapply(self, project_state, schema_editor, collect_sql=False):

    to_run = []
    new_state = project_state
    for operation in self.operations:
        if (not operation.reversible):
            raise IrreversibleError(('Operation    %s    in    %s    is    not    reversible' % (operation, self)))
        new_state = new_state.clone()
        old_state = new_state.clone()
        operation.state_forwards(self.app_label, new_state)
        to_run.insert(0, (operation, old_state, new_state))
    for (operation, to_state, from_state) in to_run:
        if collect_sql:
            schema_editor.collected_sql.append('--')
            if (not operation.reduces_to_sql):
                schema_editor.collected_sql.append('--    MIGRATION    NOW    PERFORMS    OPERATION    THAT    CANNOT    BE    WRITTEN    AS    SQL:')
            schema_editor.collected_sql.append(('--    %s' % operation.describe()))
            schema_editor.collected_sql.append('--')
            if (not operation.reduces_to_sql):
                continue
        if ((not schema_editor.connection.features.can_rollback_ddl) and operation.atomic):
            with atomic(schema_editor.connection.alias):
                operation.database_backwards(self.app_label, schema_editor, from_state, to_state)
        else:
            operation.database_backwards(self.app_label, schema_editor, from_state, to_state)
    return project_state
