php - Doctrine insists on trying to use PostgreSQLDriver despite contrary config
Get the solution ↓↓↓I am setting up a Symfony 5.2 app, usingdoctrine/doctrine-bundle
2.4 anddoctrine/orm
2.9. Mydoctrine.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: 'App\Entity'
alias: App
The problem is that when I rundoctrine: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 likeDATABASE_URL
is not available inside my Docker container, which is probably the source of the problem. I've verified thatDATABASE_URL
is defined in my.env
file, and that my.env
file is in the same folder as mydocker-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.
Answer
Solution:
I think you have a wrongDATABASE_URL
in your.env
file. Please check if it starts withmysql://
.
Answer
Solution:
I believe symfony uses dotenv package to load the values from .env to theS_ENV
superglobal. You need to debug whether your dotenv (and there is a .env in your project and it is not .env.local or .env.dist) is loaded properly.
Answer
Solution:
It has happened to me sometimes when I was starting, typically when cloning a Github project which has a default .env file created by Doctrine when it's installed through composer that by default Doctrine uses PostgreSQL URL.
See how many .env files have you document and I'm sure that someone overrides your URL connection.
See this StackOverflow post to know the difference between the .env.* files What is the difference between .env.local and .env.development.local
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function update() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.