Drush 13.3.3.0数据库连接正常但无法执行管理类命令
解决Drush无法执行
pm/cc命令但数据库连接正常的问题 问题现象
执行drush en、drush cc等命令时返回:
"command pm (or cc) was not found. Drush was unable to query your database. As a result, many commands are unavailable."
但drush status可正常显示站点、PHP版本等信息,drush sqlc也能成功连接数据库并查询表结构。执行drush cc --debug时抛出如下异常栈:
Exception trace: at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/drush/drush/src/Application.php:233 Drush\Application->bootstrapAndFind() at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/drush/drush/src/Application.php:185 Drush\Application->find() at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/symfony/console/Application.php:266 Symfony\Component\Console\Application->doRun() at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/symfony/console/Application.php:175 Symfony\Component\Console\Application->run() at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/drush/drush/src/Runtime/Runtime.php:110 Drush\Runtime\Runtime->doRun() at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/drush/drush/src/Runtime/Runtime.php:40 Drush\Runtime\Runtime->run() at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/drush/drush/drush.php:140 include() at /Applications/XAMPP/xamppfiles/htdocs/drupal10/vendor/bin/drush.php:120
排查与解决方案
1. 检查版本兼容性
确认Drush版本适配Drupal 10:Drupal 10要求Drush 11及以上版本。执行drush --version查看版本,若版本过低,运行以下命令更新:
composer require drush/drush:^11
2. 强制完整Bootstrap
drush status和sqlc仅需部分Bootstrap阶段,而pm/cc命令需要完整的Drupal Bootstrap。尝试强制触发完整Bootstrap:
drush cr --bootstrap=full
若仍报错,检查sites/default/settings.php:
- 确认
$databases配置无语法错误(即使sqlc能连接,也要保证Drupal自身调用的配置正常) - 临时注释配置中的自定义代码、模块引入,排除静默异常干扰。
3. 清理缓存与重置依赖
- 清理Drush自身缓存:
drush cache:drush-clear
- 重置Composer依赖,确保命令文件完整:
composer install --no-dev --optimize-autoloader
- 检查
vendor/drush/drush/src/Commands目录下是否存在PmCommands.php、CacheCommands.php等文件,若缺失则重新安装Drush。
4. 修复文件权限
确保站点目录权限正确,命令行用户与Web服务器用户需有对应读写权限(Mac下XAMPP默认用户组为_www:_www):
chown -R _www:_www /Applications/XAMPP/xamppfiles/htdocs/drupal10 chmod -R 755 /Applications/XAMPP/xamppfiles/htdocs/drupal10 chmod -R 775 /Applications/XAMPP/xamppfiles/htdocs/drupal10/sites/default/files
5. 定位Bootstrap错误
启用详细日志,定位Bootstrap失败的具体环节:
drush en mymodule --debug --verbose
重点查看日志中数据库查询、模块加载阶段的报错信息。
内容的提问来源于stack exchange,提问作者Walfried Veldman
相关产品推荐
相关产品推荐

