diff --git a/aleksis/apps/paweljong/migrations/0014_move_sent_to_to_through.py b/aleksis/apps/paweljong/migrations/0014_move_sent_to_to_through.py index 29212223826d3bc45a342970dd666ca7ac389b49..e7955744e634b7ac56cb96656059de0463c6d52e 100644 --- a/aleksis/apps/paweljong/migrations/0014_move_sent_to_to_through.py +++ b/aleksis/apps/paweljong/migrations/0014_move_sent_to_to_through.py @@ -12,12 +12,14 @@ def migrate_to_new_through(apps, schema_editor): db_alias = schema_editor.connection.alias - for event in Event.objects.using(db_alias).iterator(): - for info_mailing in event.info_mailings.all(): - through = Through.objects.create(event=event, info_mailing=info_mailing) - for person in info_mailing.sent_to.all(): - if EventRegistration.objects.filter(person_id=person.id, event_id=event.id).exists(): - through.sent_to.add(person) + for through_old in Event.info_mailings.through.objects.all(): + event = through_old.event + info_mailing = through_old.infomailing + + through = Through.objects.create(event=event, info_mailing=info_mailing) + for person in info_mailing.sent_to.all(): + if EventRegistration.objects.filter(person_id=person.id, event_id=event.id).exists(): + through.sent_to.add(person) class Migration(migrations.Migration):