Ticket 22788: correctly handle custom migrations in writer

As per https://code.djangoproject.com/ticket/22788, fix the migration operation writer,
so it works with custom migration operations.