Problem/Motivation
**Drupal 10.0.9**
I'm removing a custom field from an existing entity with the following code in a hook_update_N()
; executing the database update drush command I get the error:
> [error] Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getTableMapping(): Argument #2 ($storage_definitions) must be of type ?arra
y, Drupal\Core\Field\BaseFieldDefinition given, called in /var/www/html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
on line 744
Steps to reproduce
Add a custom field
function my_module_update_8001(): void {
$storage_definition = BaseFieldDefinition::create('string_long')
->setLabel(t('My field'))
->setDescription(t('My custom field.'))
->setReadOnly(TRUE)
->setDefaultValue('');
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('my_field_name', 'my_entity', 'my_module', $storage_definition);
}
then remove it
function my_module_update_8002(): void {
$update_manager = \Drupal::entityDefinitionUpdateManager();
$definition = $update_manager->getFieldStorageDefinition('my_field_name', 'my_entity');
$update_manager->uninstallFieldStorageDefinition($definition);
}
Proposed resolution
Replace line 744 in the class Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema
with
$table_mapping = $this->getTableMapping($this->entityType, [$deleted_storage_definition]);
Remaining tasks
Make the patch.
Release notes snippet
TBD