Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine DBAL 2.5 Breaks Symfony if DB Doesn't Exist #351

Closed
mattjanssen opened this issue Dec 5, 2014 · 108 comments · Fixed by doctrine/dbal#2671
Closed

Doctrine DBAL 2.5 Breaks Symfony if DB Doesn't Exist #351

mattjanssen opened this issue Dec 5, 2014 · 108 comments · Fixed by doctrine/dbal#2671
Assignees
Labels

Comments

@mattjanssen
Copy link

After updating to DBAL 2.5, Doctrine introduced Doctrine\DBAL\Connection::detectDatabasePlatform() which is different than 2.4. Now in 2.5, any time a repository is instantiated (not even used) by the DI, we get a PDOException if the DB doesn't already exist.

Imagine trying to run app/console doctrine:database:create and getting a "Database doesn't exist!" error. Repositories as services are very common in most projects, so this is a huge issue.

To illustrate quickly, create a fresh Symfony project, letting composer install the AcmeDemoBundle. Then, while trying to generate an entity, you'll get the PDOException.

composer create-project symfony/framework-standard-edition symfony-standard
cd symfony-standard
app/console doctrine:generate:entity --entity=AcmeDemoBundle:Foo
  [Doctrine\DBAL\Exception\ConnectionException]
  An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'testdb'

  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[HY000] [1049] Unknown database 'testdb'

  [PDOException]
  SQLSTATE[HY000] [1049] Unknown database 'testdb'
@guilhermeblanco
Copy link
Member

This seems because you're relying in the auto-detection of platform to be used.
Configure the platform to be used as part of DoctrineBundle and live happy. =)

@mattjanssen
Copy link
Author

I'm glad you've found a solution! But I'm struggling to put that into code. Could you help me change the above app/console doctrine:generate:entity --entity=AcmeDemoBundle:Foo command to work with your platform idea?

@guilhermeblanco
Copy link
Member

@mattjanssen
Copy link
Author

I am surprised that installing a new copy of Symfony and running app/console doctrine:generate:entity gives me an error out of the box. I am especially surprised because doctrine:generate:entity used to work right out of the box. And now it doesn't.

Please remember, I am using all of the Symfony Standard defaults. I have change nothing from the standard, so everything should just work.

Symfony documentation doesn't say you need to create a custom platform_service in order to run the doctrine:generate:entity command. I would expect this command to continue to work like it used to before DBAL 2.5. platform_service was never required until now. This is a breaking change, isn't it?

http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_doctrine_entity.html

@guilhermeblanco
Copy link
Member

@mattjanssen might be... I'm giving you a hand to address the issue right now.
Tomorrow I will discuss with others on how to fix this. =)

@deeky666
Copy link
Member

deeky666 commented Dec 5, 2014

For know you can simply provide the version of the database server you are connecting to like this:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                dbname:   Symfony2
                user:         root
                password: null
                host:         localhost
                driver:       pdo_mysql
                server_version: 5.6 # your database server version here

As a workaround until we find a solution.

@stof
Copy link
Member

stof commented Dec 5, 2014

See http://www.doctrine-project.org/jira/browse/DBAL-1057 for the DBAL issue

@mattjanssen
Copy link
Author

Thank you @deeky666, @guilhermeblanco and @stof for confirming the issue! I was afraid this would be another "me" issue that no one else was experiencing. Those get very frustrating. Can I close this one then?

@stof
Copy link
Member

stof commented Dec 5, 2014

I will keep it opened for now, until we see whether Doctrine can improve this to avoid guessing too early. I will give more visibility to this issue (and hopefully avoid too many duplicates).

@thundo
Copy link

thundo commented Dec 10, 2014

Same for me @mattjanssen.
I reverted back to DoctrineBundle 1.2 and DBAL 2.4.3 to avoid the issue.

@stof
Copy link
Member

stof commented Dec 19, 2014

@thundo you can keep using DoctrineBundle 1.3. DoctrineBundle itself is not related to this issue at all.

@alanhartless
Copy link

This is a problem for us because we use an installer UI to configure the database. Because of DBAL 2.5, the installer fails out of the box since the database isn't configured yet. In the installer, we give the option to select what driver to use and thus can't use the server_version workaround. Reverting to DBAL 2.4 was the only way fix I saw but that's not going to be an option in the long run.

@deeky666
Copy link
Member

deeky666 commented Jan 7, 2015

@alanhartless we are still working on a solution. Until then if you cannot provide the server_version option please stick to 2.4 until we fixed the issue.

@Taluu
Copy link

Taluu commented Jan 14, 2015

2.4 also shows this error... And not 2.3

I haven't tested yet with the server_version hack though.

@deeky666
Copy link
Member

@Taluu this is error is related to DBAL >= 2.5. If you get a similar error it must be something different.

@Taluu
Copy link

Taluu commented Jan 15, 2015

Well, I can't create the database on 2.4, I have the error "the database doesn't exist". So it looks like the same error.... I can drop it if it exists, but that's all.

✘ talus@zoidberg > ~/dev/web/app >  migrate-symfony > sf doctrine:database:create --force -vv

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

Exception trace:
 () at /home/talus/dev/web/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103
 Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException() at /home/talus/dev/web/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:133
 Doctrine\DBAL\DBALException::driverException() at /home/talus/dev/web/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:47
 Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /home/talus/dev/web/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
 Doctrine\DBAL\Connection->connect() at /home/talus/dev/web/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
 Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /home/talus/dev/web/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
 Doctrine\DBAL\Connection->detectDatabasePlatform() at /home/talus/dev/web/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
 Doctrine\DBAL\Connection->getDatabasePlatform() at /home/talus/dev/web/app/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:81
 Doctrine\ORM\Mapping\ClassMetadataFactory->initialize() at /home/talus/dev/web/app/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:292
 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /home/talus/dev/web/app/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:211
 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /home/talus/dev/web/app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:265
 Doctrine\ORM\EntityManager->getClassMetadata() at /home/talus/dev/web/app/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:67
 Doctrine\ORM\Repository\DefaultRepositoryFactory->createRepository() at /home/talus/dev/web/app/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:50
 Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository() at /home/talus/dev/web/app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:665
 Doctrine\ORM\EntityManager->getRepository() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:5947
 appDevDebugProjectContainer->getWisembly_Meeting_Security_Meeting_AccessRepositoryService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:6390
 appDevDebugProjectContainer->getSecurity_Access_DecisionManagerService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:2980
 appDevDebugProjectContainer->getSecurity_AuthorizationCheckerService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:2993
 appDevDebugProjectContainer->getSecurity_ContextService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:6141
 appDevDebugProjectContainer->getWisembly_RatingService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:4933
 appDevDebugProjectContainer->getWisembly_Api4_QuoteService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:4814
 appDevDebugProjectContainer->getWisembly_Api4_EventService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:4920
 appDevDebugProjectContainer->getWisembly_Api4_OrganizationService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/app/cache/dev/appDevDebugProjectContainer.php:5303
 appDevDebugProjectContainer->getWisembly_Corebundle_Listener_OrganizationService() at /home/talus/dev/web/app/app/bootstrap.php.cache:2097
 Symfony\Component\DependencyInjection\Container->get() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php:188
 Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->lazyLoad() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php:128
 Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->getListeners() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php:215
 Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->preProcess() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php:107
 Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:878
 Symfony\Component\Console\Application->doRunCommand() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/talus/dev/web/app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /home/talus/dev/web/app/app/console:22

And the server_version makes it work (even if I only put the major value, such as 5 for 5.5 or 5.6). And also for Doctrine 2.5, so this really looks like the same problem to me

@deeky666
Copy link
Member

@Taluu I can see from your stack trace that you are actually using DBAL 2.5. Therefore it's the same issue, yes.

@Taluu
Copy link

Taluu commented Jan 15, 2015

Yes, just saw on the orm's composer that 2.5 is used with the orm on 2.4 (as I have only the orm specified in my composer). So it is indeed a 2.5 error then. My bad.

@SoboLAN
Copy link

SoboLAN commented Feb 22, 2015

Is there any progress on this issue ?

I was really looking forward to DBAL 2.5 due to its support for INSERTs in QueryBuilder, but I can't upgrade unless this problem is fixed.

@mattjanssen
Copy link
Author

I think requiring first-time Symfony Standard installers to figure out that they must manually set the server_version in config.yml is asking too much of new users. I imagine people giving up on Symfony when they get nasty red errors while following the Getting Started examples.

So if parameters.yml.dist + ParameterHandler prompts them with a working default... 👍 👍 👍

@Ocramius
Copy link
Member

Ocramius commented Mar 9, 2017

Prompting: good
Pre-set version: not good

Someone make it happen ;-)

@dkarlovi
Copy link

dkarlovi commented Mar 9, 2017

@Ocramius I did set the version, of course, but it took quite some time to figure out it's even needed, that's the reason I'm following this issue to begin with. :)

@deeky666
Copy link
Member

deeky666 commented Mar 9, 2017

FYI I tried to fix this in DBAL via doctrine/dbal#2671 now thanks to the comment by @soullivaneuh which inspired me for this approach.

solazs pushed a commit to hexaaproject/hexaa-backend that referenced this issue Mar 30, 2017
v0.30.7, nohook build
Fixed a bug that could cause an ISE when some Entity was requested with
ID===null
Added database_version parameter to work around a DBAL issue (see doctrine/DoctrineBundle#351)
jmontoyaa added a commit to chamilo/chamilo-lms that referenced this issue Apr 28, 2017
@Ocramius Ocramius added the Bug label May 10, 2017
@Ocramius
Copy link
Member

Handled in doctrine/dbal#2671

fpapadopou added a commit to fpapadopou/pde that referenced this issue Jul 2, 2017
The script must be run from within the VM and will most likely fail
because of this bug
(doctrine/DoctrineBundle#351). However it
contains all necessary commands in order to install the PDE application.
MKodde added a commit to OpenConext/Stepup-Middleware that referenced this issue Sep 19, 2018
See: doctrine/DoctrineBundle#351 for more
details about the problem.
MKodde added a commit to OpenConext/Stepup-Middleware that referenced this issue Sep 19, 2018
See: doctrine/DoctrineBundle#351 for more
details about the problem.
MKodde added a commit to OpenConext/Stepup-Middleware that referenced this issue Sep 19, 2018
See: doctrine/DoctrineBundle#351 for more
details about the problem.
MKodde added a commit to OpenConext/Stepup-Middleware that referenced this issue Sep 19, 2018
See: doctrine/DoctrineBundle#351 for more
details about the problem.
HCrane added a commit to HCrane/Catroweb-Symfony that referenced this issue May 28, 2019
fladens pushed a commit to Catrobat/Catroweb that referenced this issue Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.