+ $storage = clone $this->entityTypeManager->getStorage($entity_type_id);
+
+ // Entity type definition updates can change the schema by adding or
+ // removing entity tables (for example when switching an entity type from
+ // non-revisionable to revisionable), so CRUD operations on a field storage
+ // definition need to use the last installed entity type schema.
+ if ($storage instanceof SqlContentEntityStorage
+ && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) {
+ $storage->setEntityType($last_installed_entity_type);
+ }
+