doupu0619 2017-03-02 12:22
浏览 68
已采纳

当我尝试使用Doctrine创建数据库时,为什么会出现PDOException?

First, I would like to mention the issue appears only when I try to recreate the database using php bin/console doctrine:database:create. All other Doctrine commands work.

To prove it, let's delete the database:

$ php bin/console doctrine:database:drop --force
Dropped database for connection named `my_database`

Process finished with exit code 0 at 01:59:44.
Execution time: 2 834 ms.

However, now, when I try to recreate the database with php bin/console doctrine:database:create, I get:

[PDOException]
  SQLSTATE[HY000] [1049] Unknown database 'my_database'

The doctrine configuration in config.yml:

doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

The related arguments in parameter.yml:

parameters:
    database_host: 127.0.0.1
    database_port: ~
    database_name: my_database
    database_user: root
    database_password: ~

List of Doctrine packages:

doctrine/annotations              v1.4.0  Docblock Annotations Parser
doctrine/cache                    v1.6.1  Caching library offering an object-oriented API for many cache backends
doctrine/collections              v1.4.0  Collections Abstraction library
doctrine/common                   v2.7.2  Common Library for Doctrine projects
doctrine/dbal                     v2.5.12 Database Abstraction Layer
doctrine/doctrine-bundle          1.6.7   Symfony DoctrineBundle
doctrine/doctrine-cache-bundle    1.3.0   Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle 2.3.0   Symfony DoctrineFixturesBundle
doctrine/inflector                v1.1.0  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/orm                      v2.5.6  Object-Relational-Mapper for PHP
  • 写回答

1条回答 默认 最新

  • doujia7779 2017-03-02 12:22
    关注

    This issue can appear when using Doctrine DBAL 2.5, as stated in the Symfony documentation:

    The server_version option was added in Doctrine DBAL 2.5 ... 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.

    So we have to define the database server version in config.yml:

    doctrine:
        dbal:
            server_version: 5.7
    

    To find you server version, you can:

    • use mysql -V for MySQL
    • use postgres -V or psql -V for PostgreSQL
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn