from django.db import migrations def normalize_polls(apps, schema_editor): Note = apps.get_model('notes', 'Note') Poll = apps.get_model('notes', 'Poll') polls = Note.objects.filter(kind='poll') polls.update(is_public=True) for note in polls.iterator(): note.recipients.clear() Poll.objects.update(closes_at=None) class Migration(migrations.Migration): dependencies = [('notes', '0004_alter_note_kind_poll_polloption_pollvote_and_more')] operations = [ migrations.RunPython(normalize_polls, migrations.RunPython.noop), ]