What is the correct order of disabling the default contact form on Drupal? Drupal comes with a default contact form on each site we install. And while we already have the webforms and recaptcha module installed, some of our site owners still use the default contact form found in
/admin/structure/contact.
I need to remove them because when they are enabled, the site is prone to spam attacks. I've had a few instances where some of the sites had form submissions with PDF file uploads of inappropriate content. So you see how this is a security risk for our organization.
I removed that contact form in my local site by disabling the following modules in this order:

contact form
contact storage
contact

But I need to do this for all our sites now, so I wrote the following in my hook_update_n() function:
function my_profile_update_8011() {
    $config = \Drupal::configFactory();
    $moduleHandler = \Drupal::service('module_handler');

    if($moduleHandler-&gt;moduleExists('lightning_contact_form')) {
        Drupal::service('module_installer')-&gt;uninstall(['lightning_contact_form']);
    }
    if($moduleHandler-&gt;moduleExists('contact_storage')) {
        Drupal::service('module_installer')-&gt;uninstall(['contact_storage']);
    }
    if($moduleHandler-&gt;moduleExists('contact')) {
        Drupal::service('module_installer')-&gt;uninstall(['contact']);
    }

}

When I deployed this update to our dev environment, it would work on most of the sites, but fail on the rest. They all have this same error message:
The error output from the server was: &gt;  [notice] Update started: my_profile_update_8011
&gt;  [error]  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause': SELECT 1 AS expression
&gt; FROM
&gt; {contact_message} t
&gt; WHERE id IS NOT NULL
&gt; LIMIT 1 OFFSET 0; Array
&gt; (
&gt; )
&gt;  
&gt;  [error]  Update failed: my_profile_update_8011
 [error]  Update aborted by: my_profile_update_8011
 [error]  Finished performing updates.

All our sites share the same codebase, so I don't know where my update hook went wrong.
Is there a better way of disabling these modules?
thanks,
Kevin
You may be able to use this (untested) approach in your hook_update_N() implementation:
function my_profile_update_8011() {
  $config = \Drupal::configFactory();
  $moduleHandler = \Drupal::service('module_handler');

  $mods_removable = [
    'lightning_contact_form',
    'contact_storage',
    'contact',
  ];

  // Read the configuration.
  $module_data = $config-&gt;getEditable('core.extension')-&gt;get('module');

  foreach ($mods_removable as $module) {
    if($moduleHandler-&gt;moduleExists($module)) {
      // Unset the modules you do not need.
      unset($module_data[$module]);  
    }

  // Write the configuration.
  $config-&gt;getEditable('core.extension')-&gt;set('module', $module_data)-&gt;save();
  }

See this answer for additional info.