Symfony 5 - “驱动程序发生异常:找不到驱动程序”

新手上路,请多包涵

我目前面临这个问题。我是 Symfony 的新手。

问题:当我使用 cli symfony console doctrine:database:create 创建一个新数据库时,我收到以下错误:

 In AbstractPostgreSQLDriver.php line 102:

  An exception occurred in driver: could not find driver

In Exception.php line 18:

  could not find driver

In PDOConnection.php line 38:

  could not find driver

我正在使用带有 xampp 的 php 7.4 并且安装了正常的 pdo_sql :

 extension=bz2
extension=curl
;extension=ffi
;extension=ftp
extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop

这是我的 .env 文件配置:

 ###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://root:@127.0.0.1:3306/dbname"
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

这是我的教义.yaml 文件配置:

 doctrine:
dbal:
    url: '%env(resolve:DATABASE_URL)%'
    # IMPORTANT: You MUST configure your server version,
    # either here or in the DATABASE_URL env var (see .env file)
    #server_version: '13'
orm:
    auto_generate_proxy_classes: true
    naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
    auto_mapping: true
    mappings:
        App:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App

我一直在寻找几个小时,但我无法找到任何解决方案来解决我的问题,有人有想法吗?我在窗户上。

非常感谢 !

原文由 Thierry 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 866
2 个回答

如果你想使用 Mysql ,注释这一行 DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" 如果不注释另一行

原文由 Micka Bup 发布,翻译遵循 CC BY-SA 4.0 许可协议

就我而言,我从同事那里得到了我的 .env.local 文件并愚蠢地保存了它而没有前导点,因此 Symfony 使用来自 .env 文件的值,该文件读取为 DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8" 而不是正确的 DATABASE_URL="mysql://foo:bar@127.0.0.1:3306/baz?serverVersion=mariadb-x.y.z" 来自 .env.local

原文由 Jon Green 发布,翻译遵循 CC BY-SA 4.0 许可协议