Skip to content
Advertisement

Doctrine insists on trying to use PostgreSQLDriver despite contrary config

I am setting up a Symfony 5.2 app, using doctrine/doctrine-bundle 2.4 and doctrine/orm 2.9. My doctrine.yaml config file looks like this:

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        driver: 'pdo_mysql'
        server_version: '5.7'
        # 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: 'AppEntity'
                alias: App

The problem is that when I run doctrine:fixtures:load, I get the following output:

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 39:

  could not find driver

It looks like Doctrine is trying to use the Postgre driver, though I have specified MySQL. Is there another place where I need to configure this? If so, how?

===

EDIT: It looks like DATABASE_URL is not available inside my Docker container, which is probably the source of the problem. I’ve verified that DATABASE_URL is defined in my .env file, and that my .env file is in the same folder as my docker-compose.yml file. Also, I have a setting like this for the environment variable in that docker-compose file:

environment:
  - DATABASE_URL

So I’m not quite sure what’s wrong here.

Advertisement

Answer

I think you have a wrong DATABASE_URL in your .env file. Please check if it starts with mysql://.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement