How to uninstall a module that has added a basefield that has data My module adds a basefield 'myfield' to the core 'file' content entity.

I now need to uninstall my module for development purposes, but I can't because drush refuses to uninstall the module, saying "There is data for the field myfield on entity type File".

My understanding is that this is a known issue:


Because my module adds this field to an entity it does not own, this uninstallation will not be taken care of automatically by the core uninnstall procedure, 
Therefore my module needs to have a hook_uninstall that triggers field uninstallation using  \Drupal::entityDefinitionUpdateManager()->uninstallFieldStorageDefinition
However, a field can't be uninstalled if it still has data in it, so I first need to remove the data.
But the system to purge field data currently only works for bundle fields not base fields.
There may be other ways to delete field data, but they won't scale to large quantities of data. 
Therefore there is no robust way to uninstall my module and Drupal core is correct to refuse to uninstall it.


Given all that, how best can I uninstall it when I need to do so for development purposes (short of reinstalling Drupal)?

Here is how I am creating it:

In mymodule.module:

function mymodule_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  if ($entity_type-&gt;id() == 'file') {
    $fields = array();
    $fields['myfield'] = BaseFieldDefinition::create('boolean')
      -&gt;setLabel(t('My field'))
    return $fields;
  }
}


In mymodule.install:

  $entity_manager = \Drupal::entityManager();
  $definition = $entity_manager-&gt;getFieldStorageDefinitions('file')['myfield'];
  $entity_manager-&gt;onFieldStorageDefinitionCreate($definition);
This is a known Drupal Core limitation that looks close to being ready so hopefully will be fixed in D8.5.  In the meantime you could apply the patch linked to the issue.