diff --git a/care/facility/migrations/0346_add_recommend_discharge_action.py b/care/facility/migrations/0346_add_recommend_discharge_action.py index 23f56aa873..c464c6f60e 100644 --- a/care/facility/migrations/0346_add_recommend_discharge_action.py +++ b/care/facility/migrations/0346_add_recommend_discharge_action.py @@ -3,10 +3,16 @@ def update_recommend_discharge(apps, schema_editor): patient_model = apps.get_model("facility", "PatientRegistration") + patient_objs = [] for patient in patient_model.objects.all(): - if patient.last_consultation.last_daily_round.recommend_discharge: + if ( + patient.last_consultation + and patient.last_consultation.last_daily_round + and patient.last_consultation.last_daily_round.recommend_discharge + ): patient.action = 90 - patient.save() + patient_objs.append(patient) + patient_model.objects.bulk_update(patient_objs, ["action"]) class Migration(migrations.Migration):