Database migrations in Symfony can be performed using Doctrine Migrations Bundle. Here is a step-by-step guide on how to perform database migrations in Symfony:
Install Doctrine Migrations Bundle by running the following command in your Symfony project directory:
composer require doctrine/doctrine-migrations-bundle
Enable the bundle in your config/bundles.php
file by adding the following line:
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Create a new migration class by running the following command:
php bin/console make:migration
Update the generated migration class in the src/Migrations/VersionXXXXXXXXXXXXXX.php
file. Add your schema changes in the up
and down
methods of the migration class.
Run the migration to apply the changes to the database by executing the following command:
php bin/console doctrine:migrations:migrate
To roll back a migration, you can run the following command:
php bin/console doctrine:migrations:migrate prev
You can view the status of migrations by running the following command:
php bin/console doctrine:migrations:status
By following these steps, you can easily perform database migrations in Symfony using Doctrine Migrations Bundle.