我最近将Laminas 项目从doctrine-migrations 1.4 升级到3.6,并将doctrine-orm-module 从1 升级到5.3。在我的部署服务器上,运行
./vendor/bin/doctrine-module sync-metadata-storage
时,我收到以下错误:
Fatal error: Uncaught Doctrine\DBAL\Exception: The given 'driverClass' Doctrine\DBAL\Driver\PDO\MySql\Driver has to implement the Doctrine\DBAL\Driver interface. in /var/www/vendor/doctrine/dbal/src/Exception.php:98
Stack trace:
#0 /var/www/vendor/doctrine/dbal/src/DriverManager.php(229): Doctrine\DBAL\Exception::invalidDriverClass('Doctrine\\DBAL\\D...')
#1 /var/www/vendor/doctrine/dbal/src/DriverManager.php(185): Doctrine\DBAL\DriverManager::createDriver(NULL, 'Doctrine\\DBAL\\D...')
#2 /var/www/vendor/doctrine/doctrine-orm-module/src/Service/DBALConnectionFactory.php(62): Doctrine\DBAL\DriverManager::getConnection(Array, Object(Doctrine\ORM\Configuration), Object(Doctrine\Common\EventManager))
#3 /var/www/vendor/doctrine/doctrine-module/src/ServiceFactory/AbstractDoctrineServiceFactory.php(41): DoctrineORMModule\Service\DBALConnectionFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), 'doctrine.connec...')
#4 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(620): DoctrineModule\ServiceFactory\AbstractDoctrineServiceFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), 'doctrine.connec...', NULL)
#5 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(242): Laminas\ServiceManager\ServiceManager->doCreate('doctrine.connec...')
#6 /var/www/vendor/doctrine/doctrine-orm-module/src/Service/RunSqlCommandFactory.php(20): Laminas\ServiceManager\ServiceManager->get('doctrine.connec...')
#7 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(620): DoctrineORMModule\Service\RunSqlCommandFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), 'doctrine.dbal_c...', NULL)
#8 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(242): Laminas\ServiceManager\ServiceManager->doCreate('doctrine.dbal_c...')
#9 /var/www/vendor/doctrine/doctrine-orm-module/src/CliConfigurator.php(81): Laminas\ServiceManager\ServiceManager->get('doctrine.dbal_c...')
#10 /var/www/vendor/doctrine/doctrine-orm-module/src/Module.php(39): DoctrineORMModule\CliConfigurator->configure(Object(Symfony\Component\Console\Application))
#11 /var/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(320): DoctrineORMModule\Module::DoctrineORMModule\{closure}(Object(Laminas\EventManager\Event))
#12 /var/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(143): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\EventManager\Event))
#13 /var/www/vendor/doctrine/doctrine-module/src/Service/CliFactory.php(52): Laminas\EventManager\EventManager->trigger('loadCli.post', Object(Symfony\Component\Console\Application), Array)
#14 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(620): DoctrineModule\Service\CliFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), 'doctrine.cli', NULL)
#15 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(242): Laminas\ServiceManager\ServiceManager->doCreate('doctrine.cli')
#16 /var/www/vendor/doctrine/doctrine-module/bin/doctrine-module.php(44): Laminas\ServiceManager\ServiceManager->get('doctrine.cli')
#17 /var/www/vendor/doctrine/doctrine-module/bin/doctrine-module(4): include('/var/www/vendor...')
#18 /var/www/vendor/bin/doctrine-module(120): include('/var/www/vendor...')
#19 {main}
Next Laminas\ServiceManager\Exception\ServiceNotCreatedException: Service with name "doctrine.connection.orm_default" could not be created. Reason: The given 'driverClass' Doctrine\DBAL\Driver\PDO\MySql\Driver has to implement the Doctrine\DBAL\Driver interface. in /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:627
Stack trace:
#0 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(242): Laminas\ServiceManager\ServiceManager->doCreate('doctrine.connec...')
#1 /var/www/vendor/doctrine/doctrine-orm-module/src/Service/RunSqlCommandFactory.php(20): Laminas\ServiceManager\ServiceManager->get('doctrine.connec...')
#2 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(620): DoctrineORMModule\Service\RunSqlCommandFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), 'doctrine.dbal_c...', NULL)
#3 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(242): Laminas\ServiceManager\ServiceManager->doCreate('doctrine.dbal_c...')
#4 /var/www/vendor/doctrine/doctrine-orm-module/src/CliConfigurator.php(81): Laminas\ServiceManager\ServiceManager->get('doctrine.dbal_c...')
#5 /var/www/vendor/doctrine/doctrine-orm-module/src/Module.php(39): DoctrineORMModule\CliConfigurator->configure(Object(Symfony\Component\Console\Application))
#6 /var/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(320): DoctrineORMModule\Module::DoctrineORMModule\{closure}(Object(Laminas\EventManager\Event))
#7 /var/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(143): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\EventManager\Event))
#8 /var/www/vendor/doctrine/doctrine-module/src/Service/CliFactory.php(52): Laminas\EventManager\EventManager->trigger('loadCli.post', Object(Symfony\Component\Console\Application), Array)
#9 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(620): DoctrineModule\Service\CliFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), 'doctrine.cli', NULL)
#10 /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(242): Laminas\ServiceManager\ServiceManager->doCreate('doctrine.cli')
#11 /var/www/vendor/doctrine/doctrine-module/bin/doctrine-module.php(44): Laminas\ServiceManager\ServiceManager->get('doctrine.cli')
#12 /var/www/vendor/doctrine/doctrine-module/bin/doctrine-module(4): include('/var/www/vendor...')
#13 /var/www/vendor/bin/doctrine-module(120): include('/var/www/vendor...')
#14 {main}
thrown in /var/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 627
奇怪的是,使用相同的composer.json 设置的本地计算机上不会出现此问题。两个系统都使用相同的 PHP 版本和扩展。
我已经尝试了典型的调试步骤,包括清除各种缓存、删除供应商目录和composer.lock文件,甚至两台机器上的整个docker容器,确保环境之间的版本匹配,以及检查配置。然而我还是没能解决这个问题。
任何提示将不胜感激。
PDO\MySql\Driver
?首先检查 Doctrine 配置文件(通常位于配置目录中)中的“driverClass
”参数是否设置正确。可能是 Doctrine\DBAL\Driver\PDOMySql\Driver
,一个实现 Doctrine\DBAL\Driver
接口的类。
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => Doctrine\DBAL\Driver\PDOMySql\Driver::class,
],
],
],
然后清除 Doctrine 缓存以确保旧配置没有被使用,并重新生成 Composer 自动加载文件以确保所有类都正确自动加载:
./vendor/bin/doctrine-module orm:clear-cache:metadata
composer dump-autoload
Class 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver' not found
”中所示,检查您的 doctrine/dbal
版本。