How to execute MySQL DB migrations with Symfony and Doctrine

Nov 16, 2021 · 1 min read · Post a comment

If you are working on infrastructure with a lot of microservices as a developer you may face difficulties executing SQL queries in terms of keeping database structure clean and safe cause there is a chance to miss or elude something. Essentially, if the microservices are written in Symfony then you should thank to Doctrine which offers set of PHP libraries to work with DB migrations.

So, instead of executing SQL queries, you can use migrations which is necessary when your application begins to scale up. Here I will show you some basic doctrine commands.


  • Symfony

Doctrine Database migrations example

Step 1. If your microservices are Dockerized you need to get inside the container and navigate to the project path. So if there are migrations that are not being fetched by the other services, run:

bin/console doctrine:migrations:migrate

Step 2. To see a list of all the different options that you can do, run:

bin/console list

Step 3. If you need to find Symfony commands that are handling the table creation, delete, insert, migration on a specific entity, run:

bin/console list doctrine


In most cases, you will have the database structure and the most used command will be the first one about the migration. If you have some other questions don’t hesitate to raise them. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.