diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index a2c94fd97a..7f9fe4dccd 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -617,9 +617,12 @@ protected function getSelectQueryForFieldStorageDeletion($table_name, array $sha $select->addExpression(':delta', 'delta', [':delta' => 0]); // Add all the dynamic field columns. + $or = $select->orConditionGroup(); foreach ($shared_table_field_columns as $field_column_name => $schema_column_name) { $select->addField('entity_table', $schema_column_name, $dedicated_table_field_columns[$field_column_name]); + $or->isNotNull($schema_column_name); } + $select->condition($or); // Lock the table rows. $select->forUpdate(TRUE); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php index befcca46f9..11b79b3d92 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php @@ -395,6 +395,11 @@ public function testBaseFieldDeleteWithExistingData() { $storage = $this->entityManager->getStorage('entity_test_update'); $schema_handler = $this->database->schema(); + // Create an entity without the base field, to ensure NULL values are not + // added to the dedicated table storage to be purged. + $entity = $storage->create(); + $entity->save(); + // Add the base field and run the update. $this->addBaseField(); $this->entityDefinitionUpdateManager->applyUpdates();