{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/19589","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/19589/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/19589/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/19589/events","html_url":"https://github.com/symfony/symfony/issues/19589","id":170407066,"number":19589,"title":"[DoctrineBridge] doctrine:database:create command cannot create a database without a database","user":{"login":"mkruk-u2","id":13467160,"avatar_url":"https://avatars.githubusercontent.com/u/13467160?v=3","gravatar_id":"","url":"https://api.github.com/users/mkruk-u2","html_url":"https://github.com/mkruk-u2","followers_url":"https://api.github.com/users/mkruk-u2/followers","following_url":"https://api.github.com/users/mkruk-u2/following{/other_user}","gists_url":"https://api.github.com/users/mkruk-u2/gists{/gist_id}","starred_url":"https://api.github.com/users/mkruk-u2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkruk-u2/subscriptions","organizations_url":"https://api.github.com/users/mkruk-u2/orgs","repos_url":"https://api.github.com/users/mkruk-u2/repos","events_url":"https://api.github.com/users/mkruk-u2/events{/privacy}","received_events_url":"https://api.github.com/users/mkruk-u2/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-10T12:40:34Z","updated_at":"2016-08-10T15:18:09Z","closed_at":"2016-08-10T15:18:08Z","body":"Creating a database using `doctrine:database:create` command in the `prod` environment when there is no cache, fails with a message:\r\n\r\n```shell\r\n[Doctrine\\DBAL\\Exception\\ConnectionException]                                      \r\nAn exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'symfony'\r\n```\r\n\r\ni.e. you need a database to create a database (!)\r\n\r\nSteps to reproduce this problem:\r\n\r\n1. create new project\r\n  ```shell\r\n$ symfony new my_project_name\r\n\r\n Downloading Symfony...\r\n ...\r\n\r\n Preparing project...\r\n\r\n ✔  Symfony 3.1.3 was successfully installed.\r\n ...\r\n\r\n$ cd my_project_name/\r\n$ cat app/config/parameters.yml  # check database connection configuration\r\n# This file is auto-generated during the composer install\r\nparameters:\r\n    database_host: 127.0.0.1\r\n    database_port: null\r\n    database_name: symfony\r\n    database_user: root\r\n    database_password: null\r\n    mailer_transport: smtp\r\n    mailer_host: 127.0.0.1\r\n    mailer_user: null\r\n    mailer_password: null\r\n    secret: b9dcd0638212ee83b89aa79b04b4233bf14f79d3\r\n  ```\r\n\r\n1. generate simple entity class\r\n  ```shell\r\n$ bin/console doctrine:generate:entity --entity=AppBundle:Post --format=annotation --fields=\"title:string(255)\" --no-interaction\r\n\r\n  Entity generation\r\n\r\n> Generating entity class src/AppBundle/Entity/Post.php: OK!\r\n> Generating repository class src/AppBundle/Repository/PostRepository.php: OK!\r\n\r\n  Everything is OK! Now get to work :).\r\n  ```\r\n\r\n1. remove cache\r\n  ```shell\r\n$ rm -rf var/cache/*\r\n  ```\r\n\r\n1. try to create `prod` database\r\n  ```shell\r\n  [Doctrine\\DBAL\\Exception\\ConnectionException]\r\n  An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'symfony'\r\n\r\n  [Doctrine\\DBAL\\Driver\\PDOException]\r\n  SQLSTATE[HY000] [1049] Unknown database 'symfony'\r\n\r\n  [PDOException]\r\n  SQLSTATE[HY000] [1049] Unknown database 'symfony'\r\n  ```\r\n\r\nInteresting thing is that trying to create database again, just after previous attempt failed, is successful:\r\n```shell\r\n$ bin/console doctrine:database:create --env=prod\r\nCreated database `symfony` for connection named default\r\n```\r\n\r\nAlso, the `doctrine:database:create` command is not the only command that fails. Simple `cache:clear` also fails with the same error:\r\n```shell\r\n$ bin/console cache:clear --env=prod\r\n\r\n // Clearing the cache for the prod environment with debug false\r\n\r\n  [Doctrine\\DBAL\\Exception\\ConnectionException]\r\n  An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'symfony'\r\n\r\n  [Doctrine\\DBAL\\Driver\\PDOException]\r\n  SQLSTATE[HY000] [1049] Unknown database 'symfony'\r\n\r\n  [PDOException]\r\n  SQLSTATE[HY000] [1049] Unknown database 'symfony'\r\n\r\ncache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>\r\n```\r\n\r\n### More information\r\n\r\nWe know that adding `server_version` option to doctrine db connection settings fixes this error, but since there is auto-detection functionality built-in into Doctrine (which doesn't work in this case, because driver tries to connect to database with provided database name) it seems to be not needed.\r\n\r\n\r\nWhole stacktrace after running `doctrine:database:create` with `--verbose` option:\r\n\r\n```shell\r\n$ bin/console doctrine:database:create --env=prod --verbose\r\n\r\n  [Doctrine\\DBAL\\Exception\\ConnectionException]                                      \r\n  An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'symfony'  \r\n\r\nException trace:\r\n () at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103\r\n Doctrine\\DBAL\\Driver\\AbstractMySQLDriver->convertException() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:133\r\n Doctrine\\DBAL\\DBALException::driverException() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:47\r\n Doctrine\\DBAL\\Driver\\PDOMySql\\Driver->connect() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360\r\n Doctrine\\DBAL\\Connection->connect() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429\r\n Doctrine\\DBAL\\Connection->getDatabasePlatformVersion() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389\r\n Doctrine\\DBAL\\Connection->detectDatabasePlatform() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328\r\n Doctrine\\DBAL\\Connection->getDatabasePlatform() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->getTargetPlatform() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->completeIdGeneratorMapping() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->doLoadMetadata() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->loadMetadata() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->loadMetadata() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getMetadataFor() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:115\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getAllMetadata() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:69\r\n Symfony\\Bridge\\Doctrine\\CacheWarmer\\ProxyCacheWarmer->warmUp() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48\r\n Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerAggregate->warmUp() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:489\r\n Symfony\\Component\\HttpKernel\\Kernel->initializeContainer() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:117\r\n Symfony\\Component\\HttpKernel\\Kernel->boot() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68\r\n Symfony\\Bundle\\FrameworkBundle\\Console\\Application->doRun() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117\r\n Symfony\\Component\\Console\\Application->run() at /symfony/my_project_name/bin/console:29\r\n\r\n  [Doctrine\\DBAL\\Driver\\PDOException (1049)]         \r\n  SQLSTATE[HY000] [1049] Unknown database 'symfony'  \r\n\r\nException trace:\r\n () at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47\r\n Doctrine\\DBAL\\Driver\\PDOConnection->__construct() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:41\r\n Doctrine\\DBAL\\Driver\\PDOMySql\\Driver->connect() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360\r\n Doctrine\\DBAL\\Connection->connect() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429\r\n Doctrine\\DBAL\\Connection->getDatabasePlatformVersion() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389\r\n Doctrine\\DBAL\\Connection->detectDatabasePlatform() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328\r\n Doctrine\\DBAL\\Connection->getDatabasePlatform() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->getTargetPlatform() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->completeIdGeneratorMapping() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->doLoadMetadata() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->loadMetadata() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->loadMetadata() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getMetadataFor() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:115\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getAllMetadata() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:69\r\n Symfony\\Bridge\\Doctrine\\CacheWarmer\\ProxyCacheWarmer->warmUp() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48\r\n Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerAggregate->warmUp() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:489\r\n Symfony\\Component\\HttpKernel\\Kernel->initializeContainer() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:117\r\n Symfony\\Component\\HttpKernel\\Kernel->boot() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68\r\n Symfony\\Bundle\\FrameworkBundle\\Console\\Application->doRun() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117\r\n Symfony\\Component\\Console\\Application->run() at /symfony/my_project_name/bin/console:29\r\n\r\n  [PDOException (1049)]                              \r\n  SQLSTATE[HY000] [1049] Unknown database 'symfony'  \r\n\r\nException trace:\r\n () at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43\r\n PDO->__construct() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43\r\n Doctrine\\DBAL\\Driver\\PDOConnection->__construct() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:41\r\n Doctrine\\DBAL\\Driver\\PDOMySql\\Driver->connect() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360\r\n Doctrine\\DBAL\\Connection->connect() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429\r\n Doctrine\\DBAL\\Connection->getDatabasePlatformVersion() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389\r\n Doctrine\\DBAL\\Connection->detectDatabasePlatform() at /symfony/my_project_name/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328\r\n Doctrine\\DBAL\\Connection->getDatabasePlatform() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->getTargetPlatform() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->completeIdGeneratorMapping() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->doLoadMetadata() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->loadMetadata() at /symfony/my_project_name/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78\r\n Doctrine\\ORM\\Mapping\\ClassMetadataFactory->loadMetadata() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getMetadataFor() at /symfony/my_project_name/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:115\r\n Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getAllMetadata() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:69\r\n Symfony\\Bridge\\Doctrine\\CacheWarmer\\ProxyCacheWarmer->warmUp() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48\r\n Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerAggregate->warmUp() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:489\r\n Symfony\\Component\\HttpKernel\\Kernel->initializeContainer() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:117\r\n Symfony\\Component\\HttpKernel\\Kernel->boot() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68\r\n Symfony\\Bundle\\FrameworkBundle\\Console\\Application->doRun() at /symfony/my_project_name/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117\r\n Symfony\\Component\\Console\\Application->run() at /symfony/my_project_name/bin/console:29\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/238900361","html_url":"https://github.com/symfony/symfony/issues/19589#issuecomment-238900361","issue_url":"https://api.github.com/repos/symfony/symfony/issues/19589","id":238900361,"user":{"login":"jakzal","id":190447,"avatar_url":"https://avatars.githubusercontent.com/u/190447?v=3","gravatar_id":"","url":"https://api.github.com/users/jakzal","html_url":"https://github.com/jakzal","followers_url":"https://api.github.com/users/jakzal/followers","following_url":"https://api.github.com/users/jakzal/following{/other_user}","gists_url":"https://api.github.com/users/jakzal/gists{/gist_id}","starred_url":"https://api.github.com/users/jakzal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakzal/subscriptions","organizations_url":"https://api.github.com/users/jakzal/orgs","repos_url":"https://api.github.com/users/jakzal/repos","events_url":"https://api.github.com/users/jakzal/events{/privacy}","received_events_url":"https://api.github.com/users/jakzal/received_events","type":"User","site_admin":false},"created_at":"2016-08-10T15:18:08Z","updated_at":"2016-08-10T15:18:08Z","body":"Even though the doctrine cache warmer is part of this repo, it's not a problem with the cache warmer. It merely calls the doctrine code which in turn connects to db while it shouldn't."}}
{"actor":{"display_login":"jakzal"}}