9951 explained code solutions for 126 technologies


php-symfonyHow to create a migration in PHP Symfony?


Creating a migration in PHP Symfony is a simple process.

Create a migration class in the src/Migrations directory:

<?php

namespace App\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200101000000 extends AbstractMigration
{
    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
    }
}

Generate the SQL code for the migration:

$ php bin/console doctrine:migrations:diff

Execute the migration:

$ php bin/console doctrine:migrations:migrate

Check the status of the migration:

$ php bin/console doctrine:migrations:status

Revert the migration if needed:

$ php bin/console doctrine:migrations:migrate prev

Helpful links

Edit this code on GitHub