[Django]-Django: Really slow RunPython migration on related models

4👍

Use subquery to update field, something similar to following as you cannot use F() function in update joining tables

Album.objects.update(
    user=Subquery(
        Band.objects.filter(
            id=OuterRef('band')
        ).values('user')[:1]
    )
)

Leave a comment