How can I uninstall a Drupal 8 module with entities in the db?

I have made a dev module that implement content entities created using the drupal console. I've added fields, views, and made some modifications. But, when I try to uninstall the module, there is a error:

The following reasons prevent the modules from being uninstalled:
There is content for the entity type: xxx

Where xxx is the entity type name. If I delete the entities manually or via code, I can disable the module. But I wanted a easier way, allowing the module to delete the entities itself. I tried using hook_uninstall(), but apparently it is called after the triggering error.

I did't found the answer googling. Maybe my wording was wrong...

Anyaway. Any help would be apreciated

1 Answer 1


There is some sort of a shortcut, but it might not be what you are looking for.

If you go the Uninstall tab of the Extend page, for all modules that define content entities you'll see:


The Remove content items link will delete all entities in a batch operation, after which you can uninstall the module. So you don't have to remove them one-by-one or from the database, but it requires some extra mouse clicks...


There is also hook_module_preuninstall($module), which might be of help for you.

  • Unfortunately, the error is thrown on the line if ($reasons = $this->validateUninstall($module_list)) {, which is before the $this->moduleHandler->invokeAll('module_preuninstall', array($module));. (and before the hook_uninstall too).
    – nimbfire
    Commented Jan 25, 2017 at 21:30
  • Ah too bad. I was somewhat expecting that would work. I suppose you will have to do it with my first idea then... Commented Jan 25, 2017 at 21:57
  • I've found another question asking the same thing, and its a known bug for now... drupal.stackexchange.com/questions/194185/…
    – nimbfire
    Commented Jan 26, 2017 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.