Doctrine Migrations命名空间错误

时间:2013-05-19 23:17:16

标签: php doctrine silex doctrine-migrations

我正在尝试在silex框架之上设置doctrine迁移。我是通过作曲家安装的。

"doctrine/dbal": "2.3.*",
"doctrine/migrations": "dev-master",

我的控制台文件:

...
$app['composer_loader']->add('Doctrine\DBAL\Migrations', __DIR__.'/../vendor/doctrine/migrations/lib/');

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    "db" => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($app['db']),
    "dialog" => new \Symfony\Component\Console\Helper\DialogHelper(),
));
$console->setHelperSet($helperSet);

$console->addCommands(array(
    // Migrations Commands
    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()
));

$console->run();

但是当我运行迁移时:status输出:

C:\htdocs\bitvenda\app>php console.php migrations:status

  [Doctrine\DBAL\Migrations\MigrationException]
  Migrations namespace must be configured in order to use Doctrine migrations
  .

我做错了什么?

1 个答案:

答案 0 :(得分:7)

正如@medina评论的那样。我错过了配置文件。我创建了yml配置文件,如下所示:

name: Doctrine Migrations
migrations_namespace: DoctrineMigrations
table_name: doctrine_migration_versions
migrations_directory: /data/DoctrineMigrations

我将配置文件路径作为参数传递,以使其正常工作。

php console.php migrations:status --configuration=config/migrations.yml

为了避免一直传递它,我将工作脚本dir更改为与配置文件相同的目录,以便doctrine迁移自动加载它

chdir(__DIR__.'/config');