doctrine / DoctrineBundle

Symfony Bundle for Doctrine ORM and DBAL
https://www.doctrine-project.org/projects/doctrine-bundle.html
MIT License
4.72k stars 454 forks source link

Database creation fails (PostgreSQL and dbal 2.5.2) #461

Closed trylika closed 8 years ago

trylika commented 9 years ago

With dbal 2.5.2 and PostgreSQL (not sure about others), when executing: app/console doctrine:database:create Results in following error:

  [Doctrine\DBAL\Exception\ConnectionException]                                             
  An exception occured in driver: SQLSTATE[08006] [7] FATAL:  database "foo" does not exist 

Configuration is basic, and worked perfectly with dbal v2.4.3, but upon notice that v2.5.2 fixes this issue #402 updated dbal, but came across this error :(

kimhemsoe commented 9 years ago

@deeky666 Do you have any idea what may cause this ?

chrisguitarguy commented 9 years ago

@trylika Are you using a url configuration parameter by chance? Instead of using the associative array?

trylika commented 9 years ago

@chrisguitarguy noup, configured by ip:

    database_host:     127.0.0.1
chrisguitarguy commented 9 years ago

I got the same error, but it was related to only using a url for the configuration. See #464

trylika commented 9 years ago

oh, i misunderstood you, but still no, we dont use url configuration parameter. doctrine configuration:

doctrine:
    dbal:
        driver:   pdo_pgsql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        mapping_types:
            [few custom mapping types]
        types:
            [few custom types]
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        dql:
            string_functions:
                [few custom string functions]
kimhemsoe commented 9 years ago

@trylika Can you post a debug trace with that error ?

trylika commented 9 years ago

@kimhemsoe full stack trace:

$ app/console doctrine:database:create --verbose

  [Doctrine\DBAL\Exception\ConnectionException]                                             
  An exception occured in driver: SQLSTATE[08006] [7] FATAL:  database "foo" does not exist  

Exception trace:
 () at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php:85
 Doctrine\DBAL\Driver\AbstractPostgreSQLDriver->convertException() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:133
 Doctrine\DBAL\DBALException::driverException() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php:66
 Doctrine\DBAL\Driver\PDOPgSql\Driver->connect() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
 Doctrine\DBAL\Connection->connect() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
 Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
 Doctrine\DBAL\Connection->detectDatabasePlatform() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
 Doctrine\DBAL\Connection->getDatabasePlatform() at /var/www/vendor/doctrine/doctrine-bundle/ConnectionFactory.php:61
 Doctrine\Bundle\DoctrineBundle\ConnectionFactory->createConnection() at /tmp/foo/cache/dev/appDevDebugProjectContainer.php:1751
 appDevDebugProjectContainer->getDoctrine_Dbal_DefaultConnectionService() at /var/www/app/bootstrap.php.cache:2155
 Symfony\Component\DependencyInjection\Container->get() at /var/www/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
 Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:128
 Doctrine\Common\Persistence\AbstractManagerRegistry->getConnection() at /var/www/vendor/doctrine/doctrine-bundle/Command/DoctrineCommand.php:66
 Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand->getDoctrineConnection() at /var/www/vendor/doctrine/doctrine-bundle/Command/CreateDatabaseDoctrineCommand.php:59
 Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand->execute() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
 Symfony\Component\Console\Command\Command->run() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:886
 Symfony\Component\Console\Application->doRunCommand() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /var/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /var/www/app/console:27

  [Doctrine\DBAL\Driver\PDOException]                       
  SQLSTATE[08006] [7] FATAL:  database "foo" does not exist  

Exception trace:
 () at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47
 Doctrine\DBAL\Driver\PDOConnection::__construct() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php:46
 Doctrine\DBAL\Driver\PDOPgSql\Driver->connect() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
 Doctrine\DBAL\Connection->connect() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
 Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
 Doctrine\DBAL\Connection->detectDatabasePlatform() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
 Doctrine\DBAL\Connection->getDatabasePlatform() at /var/www/vendor/doctrine/doctrine-bundle/ConnectionFactory.php:61
 Doctrine\Bundle\DoctrineBundle\ConnectionFactory->createConnection() at /tmp/foo/cache/dev/appDevDebugProjectContainer.php:1751
 appDevDebugProjectContainer->getDoctrine_Dbal_DefaultConnectionService() at /var/www/app/bootstrap.php.cache:2155
 Symfony\Component\DependencyInjection\Container->get() at /var/www/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
 Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:128
 Doctrine\Common\Persistence\AbstractManagerRegistry->getConnection() at /var/www/vendor/doctrine/doctrine-bundle/Command/DoctrineCommand.php:66
 Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand->getDoctrineConnection() at /var/www/vendor/doctrine/doctrine-bundle/Command/CreateDatabaseDoctrineCommand.php:59
 Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand->execute() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
 Symfony\Component\Console\Command\Command->run() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:886
 Symfony\Component\Console\Application->doRunCommand() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /var/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /var/www/app/console:27

  [PDOException]                                            
  SQLSTATE[08006] [7] FATAL:  database "foo" does not exist  

Exception trace:
 () at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
 PDO->__construct() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
 Doctrine\DBAL\Driver\PDOConnection->__construct() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php:46
 Doctrine\DBAL\Driver\PDOPgSql\Driver->connect() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
 Doctrine\DBAL\Connection->connect() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
 Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
 Doctrine\DBAL\Connection->detectDatabasePlatform() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
 Doctrine\DBAL\Connection->getDatabasePlatform() at /var/www/vendor/doctrine/doctrine-bundle/ConnectionFactory.php:61
 Doctrine\Bundle\DoctrineBundle\ConnectionFactory->createConnection() at /tmp/foo/cache/dev/appDevDebugProjectContainer.php:1751
 appDevDebugProjectContainer->getDoctrine_Dbal_DefaultConnectionService() at /var/www/app/bootstrap.php.cache:2155
 Symfony\Component\DependencyInjection\Container->get() at /var/www/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
 Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:128
 Doctrine\Common\Persistence\AbstractManagerRegistry->getConnection() at /var/www/vendor/doctrine/doctrine-bundle/Command/DoctrineCommand.php:66
 Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand->getDoctrineConnection() at /var/www/vendor/doctrine/doctrine-bundle/Command/CreateDatabaseDoctrineCommand.php:59
 Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand->execute() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:259
 Symfony\Component\Console\Command\Command->run() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:886
 Symfony\Component\Console\Application->doRunCommand() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /var/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /var/www/app/console:27

also, all current versions:

doctrine/annotations                 v1.2.7             Docblock Annotations Parser
doctrine/cache                       v1.4.2             Caching library offering an object-oriented API for many cache backends
doctrine/collections                 v1.3.0             Collections Abstraction library
doctrine/common                      v2.5.1             Common Library for Doctrine projects
doctrine/data-fixtures               v1.1.1             Data Fixtures for all Doctrine Object Managers
doctrine/dbal                        v2.5.2             Database Abstraction Layer
doctrine/doctrine-bundle             v1.4.0             Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       v1.0.1             Symfony2 Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle    v2.2.1             Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle  1.0.1              Symfony DoctrineMigrationsBundle
doctrine/inflector                   v1.0.1             Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                1.0.5              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                  dev-master 6c527d8 Database Schema migrations using Doctrine DBAL
doctrine/orm                         v2.4.8             Object-Relational-Mapper for PHP
k0pernikus commented 9 years ago

I am also experiencing this issue with mysql when using dbal 2.5. Downgrading to 2.4 works fine.

Please let me know if there is any further information I could provide.

stof commented 9 years ago

@trylika try to remove the mapping_types configuration from the bundle configuration, and register this by overwriting the getMappedDatabaseTypes in your custom types instead (which is the uptodate way to do this). I think it might solve your issue, by avoiding the usage of the platform object when creating the connection. Another alternative would be to specify the server_version in your config so that it does not need to connect to know which version of the platform should be used.

trylika commented 9 years ago

@stof sorry for delayed answer, didn't have time to fully test it, but specifying server_version or completelly removing mapping_types solves the problem, unfortunatelly, didn't had time to convert all the enums to proper type definition to test if that would work. Though, this is still a bug, but temporally this workaround works.

Tobion commented 9 years ago

Isn't this a duplicate of #351

kimhemsoe commented 8 years ago

@trylika The correct solution is to specify server version. That should solve all your issues.

glaszig commented 8 years ago

this is not limited to pgsql. also mysql. same behavior. @k0pernikus' workaround works.

dbal 2.5.4

$ env SYMFONY_ENV=test bin/console doctrine:database:create

  [Doctrine\DBAL\Exception\ConnectionException]                                                 
  An exception occured in driver: SQLSTATE[42000] [1049] Unknown database 'my_app_test'  

  [Doctrine\DBAL\Driver\PDOException]                           
  SQLSTATE[42000] [1049] Unknown database 'my_app_test'  

  [PDOException]                                                
  SQLSTATE[42000] [1049] Unknown database 'my_app_test'  

dbal 2.4.5

$ env SYMFONY_ENV=test bin/console doctrine:database:create           
Created database `my_app_test` for connection named default

as you can see, no problem with database setup or configuration. i just did a solid downgrade of doctrine/dbal.

kimhemsoe commented 8 years ago

What version of bundle?

glaszig commented 8 years ago

What version of bundle?

1.6.1

Tobion commented 8 years ago

Should be closed as duplicate of #351 as I already said.

kimhemsoe commented 8 years ago

dup of #351