已经在本地升级了Drupal9.5,在运行update.php
更新数据库的时候报如下错误:
The following theme is marked as installed in the core.extension configuration, but it is missing: kpa_theme Review the suggestions for resolving this incompatibility to repair your installation, and then re-run update.php.

这个错误导致无法升级数据库。经过调研,发现是一个乌龙,主题名称是custom_kpa,而报错却一直提示找不到kpa_theme,主题文件夹下压根儿就没有kpa_theme,最后通过修改数据库config表中的core.extension字段得到解决。
代码如下:
use Drupal\Core\Config\FileStorage;
// Load the 'core.extension' configuration.
$config = \Drupal::configFactory()->getEditable('core.extension');
// Get the current list of themes.
$themes = $config->get('theme');
// Check if 'kpa_theme' is in the list of themes.
if (isset($themes['kpa_theme'])) {
// Remove 'kpa_theme' from the list of themes.
unset($themes['kpa_theme']);
// Save the updated list of themes back to the 'core.extension' configuration.
$config->set('theme', $themes)->save();
}
// Clear all caches.
drupal_flush_all_caches();
将以上代码添加到主题文件夹下的.theme文件中,刷新一下网站页面。问题就解决了。再次运行update.php
,成功升级了数据库。
这种错误本身不会影响到网站的正常运行,只是在Status report中会显示错误记录,之所以一定要解决这个问题的原因是这个错误会导致无法升级数据库。这个网站存在时间比较长了,一直正常运行,直到我做升级的时候,这个问题才暴露出来。应该是之前这个网站的开发者的小小失误吧。
在调研过程中已知,在旧版本升级到新版本时会出现这种错误,除了会报主题(theme)找不到以外,还会报模块(module)找不到,如果遇到这种问题,首先应该把不存在的主题或模块安装上。一般模块找不到的几率大一些,这就需要下载安装找不到的模块或者更新模块。如果产生报错的主题或模块是项目中确实不需要的,也可以按上面的方式从数据库中删掉,避免产生这种错误。像我遇到的这个主题找不到的问题是极少的个例,它可能由开发人员在开发过程中的一个疏忽而造成。