Learn how to easily remove this deprecation notice in your Symfony 5 project.

How to solve Symfony 5 Deprecation Notice: not setting doctrine.dbal.override_url to true is deprecated

Upgrading components of a project or even the whole project will always introduce bugs or deprecation warnings if you are not careful. Symfony of course isn't the exception. After an upgrade of Symfony 5.1 to Symfony 5.2 (which by the way, was upgraded from 4.4 to 5.1), the following deprecation notice appeared in the deprecation notices of the project:

Not setting doctrine.dbal.override_url to true is deprecated. True is the only value that will be supported in doctrine-bundle 3.0.

[
    "exception" => Symfony\Component\ErrorHandler\Exception\SilencedErrorContext {
        #3769 
        +count: 2 
        -severity: E_USER_DEPRECATED trace: {} 
    }
]

The cause of this deprecation notice is that probably, you upgraded to a newer Symfony version and you didn't update the configuration files as well (normally, with a new project, you won't see this deprecation). So for example, if you have the same doctrine.yaml file from a Symfony 4 project and you are currently running Symfony 5, then the warning will appear as the override_url parameter won't be declared in your doctrine configuration file.

To fix it, simply open the doctrine.yaml file and create the override_url parameter under the dbal key in doctrine like this:

# app/config/packages/doctrine.yaml
doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        # Important: be sure that this parameters exists and its value is set to true
        # to fix the deprecation warning!
        override_url: true

And that's it. Clear the cache and logs if necessary and you won't see this deprecation warning again.

This property of the configuration of doctrine helps to fix a very simple problem, for example, when you define a connection URL in Symfony using the DATABASE_URL env variable for development, and you use the same server but different databases for testing, you need to override the value of the entire DATABASE_URL in your config/packages/test/doctrine.yaml file.

Happy coding ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors