Learn how to solve this Symfony 6 exception when using a different database engine than specified on the database connection string.

How to solve Symfony 6 Exception: The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue

After launching a new project that's going to be built using the new Symfony 6, I got an interesting exception after creating the basic user system for the application. This exception, is related to the metadata storage which someway is not up to date. This appeared only after using the following 2 commands to prepare the migrations and execute them:

php bin/console make:migration
php bin/console doctrine:migrations:migrate

In this article, I will explain you the cause of this exception and how to prevent it from appearing in your new project.

Solving out of sync metadata storage issue

The first thing you need to do is to run the following command to synchronize the metadata storage in your symfony application:

php bin/console doctrine:migrations:sync-metadata-storage

Running the previous command will generate the following output in your terminal:

Metadata Storage synchronized

This should solve the problem normally, but in my case it didn't. After some research, I found out that the problem was related to the database string connection in your .env file. This problem is quite new as I didn't face this problem before. When I created a Symfony 5 project, the string connection for MySQL 5.7 and MariaDB used to work just well. However, in the new version, if you use MariaDB as the database engine instead of MySQL, using a MySQL connection string like the following one when using MariaDB:

DATABASE_URL="mysql://username:[email protected]:3306/db_name?serverVersion=5.7"

Will trigger the mentioned exception. So to fix this problem, I needed to search for the version of the MariaDB instance that I'm using right now in my local environment (I was able to determine the version graphically using PHPMyAdmin as I use XAMPP, alternatively you can obtain it from the CLI):

MariaDB Version PHPMyAdmin

For more information about the database connection string, please refer to the official documentation of Symfony here. Knowing this, I was able to simply change the serverVersion parameter from the DATABASE_URL parameter like this:

DATABASE_URL="mysql://username:[email protected]:3306/db_name?serverVersion=mariadb-10.4.21"

And the project is now accessible without this tedious exception appearing everytime I try to access the database!

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.