=8.1", "doctrine/doctrine-bundle": "^2.7", "doctrine/migratio" /> =8.1", "doctrine/doctrine-bundle": "^2.7", "doctrine/migratio" /> =8.1", "doctrine/doctrine-bundle": "^2.7", "doctrine/migratio"/>

Symfony doctrine/migrations: diff is not defined

985 Views Asked by At

Running a blank project. I have currently this in my composer.json

    "require": {
        "php": ">=8.1",
        "doctrine/doctrine-bundle": "^2.7",
        "doctrine/migrations": "^3.5",
        "doctrine/orm": "^2.13",
        "test/framework-bundle": "^6.1@dev", //my fork of framework-bundle latest. 
        "symfony/runtime": "^6.1"
    },

When I run ./vendor/bin/doctrine-migrations I see following commands:

 migrations
  migrations:current                [current] Outputs the current version
  migrations:dump-schema            [dump-schema] Dump the schema for your database to a migration.
  migrations:execute                [execute] Execute one or more migration versions up or down manually.
  migrations:generate               [generate] Generate a blank migration class.
  migrations:latest                 [latest] Outputs the latest version
  migrations:list                   [list-migrations] Display a list of all available migrations and their status.
  migrations:migrate                [migrate] Execute a migration to a specified version or the latest available version.
  migrations:rollup                 [rollup] Rollup migrations by deleting all tracked versions and insert the one version that exists.
  migrations:status                 [status] View the status of a set of migrations.
  migrations:sync-metadata-storage  [sync-metadata-storage] Ensures that the metadata storage is at the latest version.
  migrations:up-to-date             [up-to-date] Tells you if your schema is up-to-date.
  migrations:version

there is no diff. Also when I try to run diff it says that command is not defined. Anyone knows what the problem is?

1

There are 1 best solutions below

0
chiborg On

The diff command needs a configured Entity Manager class. When using Symfony and the "DoctrineMigrationsBundle", that is already set up for you.

When using migrations without the bundle, you need to initialize your entity manager in a file called cli-config.php (either in the root folder of your project or in config/) Here is an example:


require 'vendor/autoload.php';

use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\Setup;
use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
use Doctrine\Migrations\Configuration\Migration\PhpFile;
use Doctrine\Migrations\DependencyFactory;

// Migrations config file, see https://www.doctrine-project.org/projects/doctrine-migrations/en/3.6/reference/configuration.html
$config = new PhpFile('migrations.php');

// Adapt to your DB connection parameters or re-use config file from your application
$dbParams = ['driver' => 'pdo_sqlite', 'memory' => true];
$connection = DriverManager::getConnection( $dbParams );

// This assumes XML mapping files, use different metadata initialization if you're using annotation/attributes
// $doctrineConfig = ORMSetup::createXMLMetadataConfiguration(
//  __DIR__ . '/path/to/your/mapping/files/',
//  true
//);

// This assumes annonations/attributes for ORM mapping
$isDev = true;
$doctrineConfig = Setup::createAnnotationMetadataConfiguration(
  __DIR__ . '/path/to/your/PHP/entity/class/files',
  $isDev
);


$entityManager = new EntityManager( $connection, $doctrineConfig );
return DependencyFactory::fromEntityManager($config, new ExistingEntityManager($entityManager));

See https://www.doctrine-project.org/projects/doctrine-migrations/en/3.6/reference/configuration.html for more information