diff --git a/app/backend/wells/migrations/0143_attach_attachments_to_wells.py b/app/backend/wells/migrations/0143_attach_attachments_to_wells.py index af7f92b95..ba7b1320f 100644 --- a/app/backend/wells/migrations/0143_attach_attachments_to_wells.py +++ b/app/backend/wells/migrations/0143_attach_attachments_to_wells.py @@ -7,8 +7,16 @@ def populate_wells_with_attachment_table(apps, schema_editor): # Get all well tag numbers that don't have an entry in WellAttachment well_tag_numbers_without_attachment = Well.objects.exclude(wellattachment__isnull=False).values_list('well_tag_number', flat=True) - well_attachments_to_create = [WellAttachment(well_tag_number=tag_number) for tag_number in well_tag_numbers_without_attachment] + well_attachments_to_create = [] + + # Iterate through each tag number and create WellAttachment instances + for tag_number in well_tag_numbers_without_attachment: + well_instance = Well.objects.get(well_tag_number=tag_number) + well_attachment_instance = WellAttachment(well_tag_number=well_instance) + well_attachments_to_create.append(well_attachment_instance) + WellAttachment.objects.bulk_create(well_attachments_to_create) + class Migration(migrations.Migration):