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. Backport of bb39037fcb from master
bb39037fcb