Fixed #22788: Ensure custom migration operations can be written.

References #22788. (https://code.djangoproject.com/ticket/22788)

This inspects the migration operation, and if it is not in the
django.db.migrations module, it adds the relevant imports to the
migration writer, and uses the correct class name.