[Solved] Drupal Drush Forced Module Uninstall

Drupal Drush forced module uninstall error and fix

When working on a Drupal site, you may encounter situations where a module simply refuses to uninstall — either through the Drupal admin UI or via Drush. This guide shows you how to force uninstall a module using Drush and recover your site.

Quick Fix — Drush Forced Module Uninstall

Use the following Drush command to forcefully remove a module from Drupal's core extension configuration:

drush cdel core.extension module.your_module_name

Replace your_module_name with the actual machine name of the module. For example, to force uninstall CiviCRM:

drush cdel core.extension module.civicrm

After running the command, clear the cache:

drush cr

Why Does This Issue Occur?

There are several reasons why a module cannot be uninstalled through normal methods:

  • Module upgrade failure — An upgrade left the module in a broken state with unexpected dependencies
  • Residual configurations — Leftover config from a previously uninstalled module causes conflicts when re-enabled
  • Misconfiguration in settings.php — The module is referenced incorrectly in the settings file
  • Module enabled but not configured — The module is active in the database but missing its required settings
  • Missing settings file — For example, CiviCRM is enabled but civicrm.settings.php is not present

What Happens When This Occurs?

When a module gets stuck in this state:

  • Running drush pmu module_name throws an error
  • The Drupal Extend page shows an error or the uninstall button is greyed out
  • The entire site may go down with an unexpected error

The error from Drush typically looks like:

The module cannot be uninstalled due to [reason]

Step-by-Step Recovery Process

Step 1 — Force Uninstall the Module

drush cdel core.extension module.your_module_name

Step 2 — Clear Drupal Cache

drush cr

Step 3 — Check Site Status

drush status

Step 4 — Check Logs for Root Cause

# Check Drupal watchdog logs
drush ws --count=20

# Check PHP error logs
tail -f /var/log/php/error.log

Quick Summary

Step Command
Force uninstall module drush cdel core.extension module.module_name
Clear cache drush cr
Check site status drush status
View recent logs drush ws --count=20

This command directly removes the module entry from Drupal's configuration, bypassing the normal uninstall hooks. It gives you immediate relief to bring the site back online, after which you can investigate the root cause through Drupal logs, PHP error logs, and your configuration settings.

Comments