diff --git a/enrol/ldap/db/install.php b/enrol/ldap/db/install.php
index <HASH>..<HASH> 100644
--- a/enrol/ldap/db/install.php
+++ b/enrol/ldap/db/install.php
@@ -96,5 +96,7 @@ function xmldb_enrol_ldap_install() {
     }
 
     // Remove a setting that's never been used at all
-    unset_config('enrol_ldap_user_memberfield');
+    if (isset($CFG->enrol_ldap_user_memberfield)) {
+        unset_config('enrol_ldap_user_memberfield');
+    }
 }
enrol/ldap: MDL-<I> don't use $CFG->enrol_ldap_user_memberfield if it's not defined