【问题标题】:Doctrine migrations not using specified configuration不使用指定配置的学说迁移
【发布时间】:2014-02-01 14:27:44
【问题描述】:

我已经在我的 ZF2 项目中使用 Doctrine and Migrations 几个星期了,没有任何问题。我一直在通过指定自己的配置文件来执行迁移:

vendor/bin/doctrine-module migrations:diff --configuration=/path/to/migrations-config.xml

我最近通过 composer 将Codeception 引入了我的项目,当我最近执行新的迁移时(使用与上述相同的命令),我收到以下错误:

[InvalidArgumentException]
Migrations directory data/DoctrineORMModule/Migrations does not exist

这不是我在配置文件中指定的目录。起初我认为 Doctrine Migrations 完全忽略了我的 --configuration 论点。当我跟踪它时,我发现 Doctrine Migrations 没有使用我的 --configuration 参数,因为它已经加载了一个配置文件。

有人知道这个配置文件是从哪里引入的吗?我可以通过在 AbstractCommand getMigrationConfiguration() 中注释掉条件来暂时解决这个问题,但从长远来看,我宁愿不必依赖这个。我还将尝试删除代码接收,看看是否有任何影响。任何帮助表示赞赏。

【问题讨论】:

    标签: doctrine-orm doctrine zend-framework2 doctrine-migrations


    【解决方案1】:

    事实证明,我能够将 Doctrine 迁移配置移动到我的 ZF2 模块配置中。在我的 module.config.php 中,我指定了以下内容(Api 是模块名称):

    'doctrine' => array(
            'driver' => array(
                'application_entities' => array(
                    'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                    'cache' => 'array',
                    'paths' => array(__DIR__ . '/../src/Api/Entity')
                ),
                'orm_default' => array(
                    'drivers' => array(
                        'Api\Entity' => 'application_entities'
                    )
                )
            ),
            'migrations_configuration' => array(
                'orm_default' => array(
                    'directory' => 'data/migrations',
                    'namespace' => 'My\Namespace\Migrations',
                    'table' => 'migrations',
                ),  
            ),
        ),
    

    这允许我运行 Doctrine 迁移命令而无需指定配置文件,例如:

    vendor/bin/doctrine-module migrations:diff
    

    【讨论】:

      【解决方案2】:

      我看到了使用独立doctrine-migration.phar 命令的替代方法:

      php doctrine-migrations.phar migrations:migrate --configuration=config.xml --db-configuration=db-config.xml

      要完成这项工作,您需要从这里下载doctrine-migrations.pharhttps://github.com/doctrine/migrations

      【讨论】:

      • 感谢您的建议。我排除了 Codeception,所以还有其他事情发生。如果我无法在我的项目中找到问题,我会考虑你的建议。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 2017-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      相关资源
      最近更新 更多