首页 > 解决方案 > 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

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

非常感谢 !

标签: sqlsymfony

解决方案


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


推荐阅读