Fix patch
diff --git a/erpnext/patches/v11_0/create_department_records_for_each_company.py b/erpnext/patches/v11_0/create_department_records_for_each_company.py
index 6f869b0..bef524c 100644
--- a/erpnext/patches/v11_0/create_department_records_for_each_company.py
+++ b/erpnext/patches/v11_0/create_department_records_for_each_company.py
@@ -67,6 +67,9 @@
 				THEN "%s"
 			'''%(employee.name, department, records[department]))
 
+	if not when_then:
+		return
+
 	frappe.db.sql("""
 		update
 			`tabInstructor`