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

[Command] doctrine:database:create does not work with commentedTypes anymore #672

Closed
elementaire opened this issue Jun 15, 2017 · 12 comments

Comments

@elementaire
Copy link

elementaire commented Jun 15, 2017

Hello,

I updated my Symfony project via the composer update command. The doctrine-bundle moved to the version 1.6.8.

But, I can't use the command php bin/console doctrine:database:create anymore. Indeed, I get this error :

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[08006] [7] FATAL:  database "project" does not exist' in /var/www/html/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
Stack trace:
#0 /var/www/html/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(43): PDO->__construct('pgsql:host=127....', 'root', 'mypassword', Array)
#1 /var/www/html/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php(46): Doctrine\DBAL\Driver\PDOConnection->__construct('pgsql:host=127....', 'root', 'mypassword', Array)
#2 /var/www/html/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(360): Doctrine\DBAL\Driver\PDOPgSql\Driver->connect(Array, 'root', 'mypassword', Array)
#3 /var/www/html/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): Doctrine\DBAL\Connection->connect()
#4 /var/www/html/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#5 /var/www/html/project in /var/www/html/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php on line 85

I tried to downgrade the version in the composer.json to 1.6.7. No error.

I am using PostgreSQL 9.4.8 (Ubuntu Unity 15.10).

Is this a bug in this tag version ?

-- edit : i corrected the version.

@Ocramius
Copy link
Member

@elementaire what dependencies changed? Can you check if the DBAL changed too?

@elementaire
Copy link
Author

@Ocramius The full log :

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 0 installs, 18 updates, 0 removals
  - Updating twig/twig (v1.33.0 => v1.34.3): Loading from cache
  - Updating symfony/polyfill-util (v1.3.0 => v1.4.0): Loading from cache
  - Updating symfony/polyfill-php70 (v1.3.0 => v1.4.0): Loading from cache
  - Updating symfony/polyfill-php56 (v1.3.0 => v1.4.0): Loading from cache
  - Updating symfony/polyfill-mbstring (v1.3.0 => v1.4.0): Loading from cache
  - Updating symfony/symfony (v3.2.7 => v3.2.9): Loading from cache
  - Updating symfony/polyfill-intl-icu (v1.3.0 => v1.4.0): Loading from cache
  - Updating doctrine/doctrine-bundle (1.6.7 => 1.6.8): Loading from cache
  - Updating gedmo/doctrine-extensions (v2.4.27 => v2.4.29): Loading from cache
  - Updating knplabs/knp-paginator-bundle (2.5.4 => v2.6.0): Loading from cache
  - Updating sensio/distribution-bundle (v5.0.18 => v5.0.20): Loading from cache
  - Updating sensio/framework-extra-bundle (v3.0.25 => v3.0.26): Loading from cache
  - Updating symfony/polyfill-apcu (v1.3.0 => v1.4.0): Loading from cache
  - Updating swiftmailer/swiftmailer (v5.4.6 => v5.4.8): Loading from cache
  - Updating symfony/swiftmailer-bundle (v2.5.4 => v2.6.2): Loading from cache
  - Updating twig/extensions (v1.4.1 => v1.5.1): Loading from cache
  - Updating symfony/phpunit-bridge (v3.2.7 => v3.3.2): Loading from cache
  - Updating friendsofsymfony/user-bundle dev-master (fda6cbe => 4f92bfb):  Checking out 4f92bfbb87

@Ocramius
Copy link
Member

Hmm, so the change is indeed only isolated in here

@elementaire
Copy link
Author

@Ocramius Found ! The issue comes from the ConnectionFactory.php file L64-L66.

The pull request which introduces the bug is #623 (cc @mikeSimonson, @stof).

My doctrine configuration is :

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_pgsql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        types:
            datetime:
                class:     AppBundle\Services\Doctrine\Type\UTCDateTimeType
                commented: true
            datetimetz:
                class:     AppBundle\Services\Doctrine\Type\UTCDateTimeType
                commented: true

I need to overwrite the default Doctrine's DateTime Types to always record in UTC the data.

@elementaire elementaire changed the title [Command] doctrine:database:create does not work with Postgresql anymore [Command] doctrine:database:create does not work with commentedTypes anymore Jun 15, 2017
@mikeSimonson
Copy link
Contributor

@elementaire Your problem is more likely related to the fact that you miss the server_version in your dbal configuration.
Before that commit it would work because the call $platform = $connection->getDatabasePlatform(); would fetch it for you and totaly defeat leazy loading.

Can you try with that configuration option ?

@elementaire
Copy link
Author

elementaire commented Jun 16, 2017

I have never heard before of the server_version option. It is too bad this variable is not mentionned in the config.yml by default.

Though, i dislike the idea to manually fix and adapt the server_version each time it changes.

It does not sound like a friendly functionnality for the developpers, because it was magic before (for bad reasons, i understand).

I feel perplexed whereas server_version fixes the issue.

-- edit : it is funny, whatever i write in this variable (Eg. 9.4.8, 9.4, 9, 5, 2, ...), it solves the bug.

@Aerendir
Copy link

Same issue, same bundle version... Symfony 3.3.*

I don't know if it is relevant, but the database name is wrong in my exception message: it is all lowercase while I'm naming my database in CamelCase.

Trying with server_version...

@Aerendir
Copy link

As stated in documentation:

The server_version option was added in Doctrine DBAL 2.5, which is used by DoctrineBundle 1.3. The value of this option should match your database server version (use postgres -V or psql -V command to find your PostgreSQL version and mysql -V to get your MySQL version).

If you don't define this option and you haven't created your database yet, you may get PDOException errors because Doctrine will try to guess the database server version automatically and none is available.

@Aerendir
Copy link

Anyway, this is a parameter that should be added to the default generated configuration of Doctrine as it is practically required...

@Nijusan
Copy link

Nijusan commented Jun 23, 2017

same issue here. what changed from version 1.6.7 to 1.6.8 that the server_version configuration got mandatory?

UPDATE: ok found it for me. this fix 99a62a7#diff-5b0dbf30dd0e8ce451fd72020914e62c caused my problem. although i use commentedTypes in my project, $platform->getDatabasePlatform() was not called until now.

@kimhemsoe
Copy link
Member

Issue solved. Closing.

@Bashar1b
Copy link

Hi there,

I have the same issue

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants