我已经通过docker设置了一个新的开发环境。我有一个symfony2(2.6)应用程序,所以我想使用app/console doctrine
方法使mysql数据库更新。如何用doctrine2创建数据库?
尚未运行
$ php app/console doctrine:database:create --if-not-exists
,当我收到此错误信息:
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[42000] [1049] Unknown database 'local_api'
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000] [1049] Unknown database 'local_api'
[PDOException]
SQLSTATE[42000] [1049] Unknown database 'local_api'
是真的,MySQL数据库不存在。我想首先创建。这里发生了什么?
我发现一个bug report for the doctrine/doctrine-bundle,但我们已经使用固定版本1.5。
我还发现一个symfony2.6 issue,但它也普遍升级后symfony2 2.7.5。
我知道我可以在将direclty连接到我的mysql数据库并运行CREATE DATABASE local_api
时创建它们,但我希望我的工作流通过doctrine2。
而只是为了是绝对肯定的问题是无关我DATABSE设置我跑:
$ mysql --host=10.10.10.10 --user=foo --password=bar
mysql> CREATE DATABASE local_api;
Query OK, 1 row affected (0.00 sec)
mysql> Bye
$ php app/console doctrine:database:create --if-not-exists
Database `local_api` for connection named default already exists. Skipped.
然后我可以删除使用
php app/console doctrine:database:drop --force
数据库然而,重建它上面再次失败提到的错误。
./app/console cache:clear
所以它似乎与Symfony2中如何initalized整个数据库堆栈:试图通过清除缓存
这errror也会发生。
的详细的错误信息是这样的:
[2015-10-06 17:26:28] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". {"uid":"c9f3fb0"}
[2015-10-06 17:26:28] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". {"uid":"c9f3fb0"}
Clearing the cache for the dev environment with debug true
Clearing outdated warmup directory
Warming up cache
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[42000] [1049] Unknown database 'local_api'
Exception trace:
() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103
Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:133
Doctrine\DBAL\DBALException::driverException() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:47
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at ~/src/api/vendor/doctrine/doctrine-bundle/ConnectionFactory.php:61
Doctrine\Bundle\DoctrineBundle\ConnectionFactory->createConnection() at ~/src/api/app/cache/de_/ap_DevDebugProjectContainer.php:1093
ap_DevDebugProjectContainer->getDoctrine_Dbal_DefaultConnectionService() at ~/src/api/app/bootstrap.php.cache:2155
Symfony\Component\DependencyInjection\Container->get() at ~/src/api/app/cache/de_/ap_DevDebugProjectContainer.php:1142
ap_DevDebugProjectContainer->getDoctrine_Orm_DefaultEntityManagerService() at ~/src/api/app/bootstrap.php.cache:2155
Symfony\Component\DependencyInjection\Container->get() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
Symfony\Bridge\Doctrine\ManagerRegistry->getService() at ~/src/api/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:226
Doctrine\Common\Persistence\AbstractManagerRegistry->getManagers() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:54
Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer->warmUp() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48
Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at ~/src/api/app/bootstrap.php.cache:2641
Symfony\Component\HttpKernel\Kernel->initializeContainer() at ~/src/api/app/bootstrap.php.cache:2411
Symfony\Component\HttpKernel\Kernel->boot() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:128
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:90
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
Symfony\Component\Console\Command\Command->run() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:886
Symfony\Component\Console\Application->doRunCommand() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at ~/src/api/app/console:27
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000] [1049] Unknown database 'local_api'
Exception trace:
() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47
Doctrine\DBAL\Driver\PDOConnection::__construct() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:45
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at ~/src/api/vendor/doctrine/doctrine-bundle/ConnectionFactory.php:61
Doctrine\Bundle\DoctrineBundle\ConnectionFactory->createConnection() at ~/src/api/app/cache/de_/ap_DevDebugProjectContainer.php:1093
ap_DevDebugProjectContainer->getDoctrine_Dbal_DefaultConnectionService() at ~/src/api/app/bootstrap.php.cache:2155
Symfony\Component\DependencyInjection\Container->get() at ~/src/api/app/cache/de_/ap_DevDebugProjectContainer.php:1142
ap_DevDebugProjectContainer->getDoctrine_Orm_DefaultEntityManagerService() at ~/src/api/app/bootstrap.php.cache:2155
Symfony\Component\DependencyInjection\Container->get() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
Symfony\Bridge\Doctrine\ManagerRegistry->getService() at ~/src/api/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:226
Doctrine\Common\Persistence\AbstractManagerRegistry->getManagers() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:54
Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer->warmUp() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48
Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at ~/src/api/app/bootstrap.php.cache:2641
Symfony\Component\HttpKernel\Kernel->initializeContainer() at ~/src/api/app/bootstrap.php.cache:2411
Symfony\Component\HttpKernel\Kernel->boot() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:128
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:90
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
Symfony\Component\Console\Command\Command->run() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:886
Symfony\Component\Console\Application->doRunCommand() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at ~/src/api/app/console:27
[PDOException]
SQLSTATE[42000] [1049] Unknown database 'local_api'
Exception trace:
() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
PDO->__construct() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
Doctrine\DBAL\Driver\PDOConnection->__construct() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:45
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at ~/src/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at ~/src/api/vendor/doctrine/doctrine-bundle/ConnectionFactory.php:61
Doctrine\Bundle\DoctrineBundle\ConnectionFactory->createConnection() at ~/src/api/app/cache/de_/ap_DevDebugProjectContainer.php:1093
ap_DevDebugProjectContainer->getDoctrine_Dbal_DefaultConnectionService() at ~/src/api/app/bootstrap.php.cache:2155
Symfony\Component\DependencyInjection\Container->get() at ~/src/api/app/cache/de_/ap_DevDebugProjectContainer.php:1142
ap_DevDebugProjectContainer->getDoctrine_Orm_DefaultEntityManagerService() at ~/src/api/app/bootstrap.php.cache:2155
Symfony\Component\DependencyInjection\Container->get() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
Symfony\Bridge\Doctrine\ManagerRegistry->getService() at ~/src/api/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:226
Doctrine\Common\Persistence\AbstractManagerRegistry->getManagers() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:54
Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer->warmUp() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48
Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at ~/src/api/app/bootstrap.php.cache:2641
Symfony\Component\HttpKernel\Kernel->initializeContainer() at ~/src/api/app/bootstrap.php.cache:2411
Symfony\Component\HttpKernel\Kernel->boot() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:128
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:90
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
Symfony\Component\Console\Command\Command->run() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:886
Symfony\Component\Console\Application->doRunCommand() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at ~/src/api/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at ~/src/api/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at ~/src/api/app/console:27
cache:clear [--no-warmup] [--no-optional-warmers]
它似乎是[symfony2.6中的一个问题](https://github.com/symfony/symfony/issues/12278),我需要检查 – k0pernikus
刚刚更新到symfony2.7.5,问题仍然存在。 – k0pernikus
只是测试,它按预期工作:第一次运行: '创建的数据库“项目”为命名default' 第二次运行连接: '数据库“项目”为命名的默认连接已经存在。跳过。“ – COil