This was a bug affected on symfony-standard that was fixed.
But not for with admin-bundle: https://github.com/doctrine/DoctrineBundle/issues/351#issuecomment-146189887
According to the stack trace and @stof comment, the admin-pool try to loads the ORM mapping for classes. That produce the issue.
What solution for that? Seperate the logic? Is ORM mapping loading necessary for route cache warming?
To reproduce: Delete your database and cache and then try command:
php app/console cache:clear
cc @rande.
@Soullivaneuh you opened this issue too fast: see my next comment: https://github.com/doctrine/DoctrineBundle/issues/351#issuecomment-146198527
So, what is the problem actually? @ORM\GeneratedValue(strategy="AUTO") on my entities?
I don't think this is an issue but the earlier loading of them AFAIK.
If this is the problem, I don't think removing the strategy is the solution.
Hi everyone,
I have got a similar issue on my current project. My application specific behaviour (loading roles from the database) make this bug really blocking.
Issue observed: When clearing the cache or running a composer install on a new project instance (no database created yet) a PDOException is raised stipulating that the database is unknown.
Issue origin: The RoutesCacheWarmUp should be optional but is not due to a typo in the isOptional() method. Therefore the RoutesCacheWarmUp is loaded each time, calling the security check, thus the DB, thus raising an exception.
PR on its way
PS: Tell me if you want me to open a separate issue
If I understand correctly, this is fixed.
@greg0ire The MR of @CharlyP didn't solve the issue for my case:
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'localhost'
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [1049] Unknown database 'localhost'
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'localhost'
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'localhost'
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [1049] Unknown database 'localhost'
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'localhost'
Can you try simply app/console -vvv ca:cl ? It should provide a better output.
@greg0ire I tried with -vvv and this is the exception trace I get.
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'localhost'
Exception trace:
() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103
Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:145
Doctrine\DBAL\DBALException::driverException() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:47
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763
Doctrine\ORM\Mapping\ClassMetadataFactory->getTargetPlatform() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616
Doctrine\ORM\Mapping\ClassMetadataFactory->completeIdGeneratorMapping() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /code/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /code/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:281
Doctrine\ORM\EntityManager->getClassMetadata() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:44
Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:698
Doctrine\ORM\EntityManager->getRepository() at /code/app/cache/de_/appDevDebugProjectContaine_.php:17051
DoctrineORMEntityManager_0000000062ed958a000000005522f2f657fe5059889b7d979d2da53b7e4d9fc2->getRepository() at /code/vendor/friendsofsymfony/user-bundle/Doctrine/UserManager.php:40
FOS\UserBundle\Doctrine\UserManager->__construct() at /code/app/cache/de_/appDevDebugProjectContaine_.php:6594
appDevDebugProjectContaine_->getFosUser_UserManagerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:13966
appDevDebugProjectContaine_->getFosUser_UserProvider_UsernameEmailService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:14177
appDevDebugProjectContaine_->getSecurity_Authentication_ManagerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:10023
appDevDebugProjectContaine_->getSecurity_AuthorizationCheckerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:13153
appDevDebugProjectContaine_->getTwigService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:4459
appDevDebugProjectContaine_->getCacheWarmerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:523
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /code/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:133
Symfony\Component\HttpKernel\Kernel->boot() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:134
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:96
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:257
Symfony\Component\Console\Command\Command->run() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:872
Symfony\Component\Console\Application->doRunCommand() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:193
Symfony\Component\Console\Application->doRun() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:92
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:124
Symfony\Component\Console\Application->run() at /code/app/console:35
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [1049] Unknown database 'localhost'
Exception trace:
() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47
Doctrine\DBAL\Driver\PDOConnection->__construct() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:41
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763
Doctrine\ORM\Mapping\ClassMetadataFactory->getTargetPlatform() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616
Doctrine\ORM\Mapping\ClassMetadataFactory->completeIdGeneratorMapping() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /code/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /code/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:281
Doctrine\ORM\EntityManager->getClassMetadata() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:44
Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:698
Doctrine\ORM\EntityManager->getRepository() at /code/app/cache/de_/appDevDebugProjectContaine_.php:17051
DoctrineORMEntityManager_0000000062ed958a000000005522f2f657fe5059889b7d979d2da53b7e4d9fc2->getRepository() at /code/vendor/friendsofsymfony/user-bundle/Doctrine/UserManager.php:40
FOS\UserBundle\Doctrine\UserManager->__construct() at /code/app/cache/de_/appDevDebugProjectContaine_.php:6594
appDevDebugProjectContaine_->getFosUser_UserManagerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:13966
appDevDebugProjectContaine_->getFosUser_UserProvider_UsernameEmailService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:14177
appDevDebugProjectContaine_->getSecurity_Authentication_ManagerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:10023
appDevDebugProjectContaine_->getSecurity_AuthorizationCheckerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:13153
appDevDebugProjectContaine_->getTwigService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:4459
appDevDebugProjectContaine_->getCacheWarmerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:523
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /code/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:133
Symfony\Component\HttpKernel\Kernel->boot() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:134
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:96
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:257
Symfony\Component\Console\Command\Command->run() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:872
Symfony\Component\Console\Application->doRunCommand() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:193
Symfony\Component\Console\Application->doRun() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:92
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:124
Symfony\Component\Console\Application->run() at /code/app/console:35
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'localhost'
Exception trace:
() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
PDO->__construct() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
Doctrine\DBAL\Driver\PDOConnection->__construct() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:41
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at /code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763
Doctrine\ORM\Mapping\ClassMetadataFactory->getTargetPlatform() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616
Doctrine\ORM\Mapping\ClassMetadataFactory->completeIdGeneratorMapping() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /code/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /code/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:281
Doctrine\ORM\EntityManager->getClassMetadata() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:44
Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository() at /code/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:698
Doctrine\ORM\EntityManager->getRepository() at /code/app/cache/de_/appDevDebugProjectContaine_.php:17051
DoctrineORMEntityManager_0000000062ed958a000000005522f2f657fe5059889b7d979d2da53b7e4d9fc2->getRepository() at /code/vendor/friendsofsymfony/user-bundle/Doctrine/UserManager.php:40
FOS\UserBundle\Doctrine\UserManager->__construct() at /code/app/cache/de_/appDevDebugProjectContaine_.php:6594
appDevDebugProjectContaine_->getFosUser_UserManagerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:13966
appDevDebugProjectContaine_->getFosUser_UserProvider_UsernameEmailService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:14177
appDevDebugProjectContaine_->getSecurity_Authentication_ManagerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:10023
appDevDebugProjectContaine_->getSecurity_AuthorizationCheckerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:13153
appDevDebugProjectContaine_->getTwigService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/app/cache/de_/appDevDebugProjectContaine_.php:4459
appDevDebugProjectContaine_->getCacheWarmerService() at /code/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:314
Symfony\Component\DependencyInjection\Container->get() at /code/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:523
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /code/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:133
Symfony\Component\HttpKernel\Kernel->boot() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:134
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:96
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:257
Symfony\Component\Console\Command\Command->run() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:872
Symfony\Component\Console\Application->doRunCommand() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:193
Symfony\Component\Console\Application->doRun() at /code/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:92
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /code/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:124
Symfony\Component\Console\Application->run() at /code/app/console:35
I found another weird case, I still getting the error when I'm trying to reproduce with this commands :
app/console cache:clearapp/console cache:clear --no-warmupapp/console -vvv cache:clearBut when I'm trying with
app/console -vvv cache:clear --no-warmupThe error is gone and I get
```[2016-12-21 11:12:50] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
[2016-12-21 11:12:50] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure".
[2016-12-21 11:12:50] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand".
[2016-12-21 11:12:50] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand".
// Clearing the cache for the dev environment with debug true
// Removing old cache directory...
// Finished
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.```
For me, the culprit is here : FOS\UserBundle\Doctrine\UserManager->__construct()
@stof also just ran into an issue where cache:clear requires a DB connection and I suspect its related to the above issue. what do you think about refactoring this bit in FOSUserBundle? I guess we should just define accessor methods for the repository/metadata so that we can do this lazy?
Is this still an issue. And if so, is this related to this bundle? If this is still relevant feel free to reopen @Soullivaneuh
Most helpful comment
@greg0ire The MR of @CharlyP didn't solve the issue for my case: