2

Doctrine Migrations で独自のDoctrine\Dbal\Connectionオブジェクトを使用しようとしましたが、これはこれまでのところ得られたものですが、 --db-configurationファイルを提供するように言われ続けていますが、これは私が望んでいるものではありません。

// CLI script for Doctrine Migrations
$app = require 'bootstrap.php';

$cli = new Symfony\Component\Console\Application('Doctrine CLI');

$cli->addCommands([
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
]);

$helperSet = new Symfony\Component\Console\Helper\HelperSet([
    // Doctrine\DBAL\Connection $app->getContainer()->db
    'connection' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($app->getContainer()->db),
    'dialog' => new \Symfony\Component\Console\Helper\QuestionHelper(),
]);

$cli->setHelperSet($helperSet);

$cli->run();

例外:

[InvalidArgumentException]                                                                                 
You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrat  
ions.  
4

1 に答える 1

0
$cli->setHelperSet($helperSet);

前に来る必要がある

$cli->addCommands([
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
    new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
]);

helperSet が各コマンドに渡されるようにします。

出典:私もこれに苦労していました。コードを掘り下げて、自分の間違いに気付くまでどのように機能するかを確認しました(これはあなたのものと同じであり、この質問への将来の訪問者の可能性があります。)

于 2018-08-25T00:42:55.147 に答える