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:
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:
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):
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:
And the project is now accessible without this tedious exception appearing everytime I try to access the database!
Happy coding ❤️!