首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Symfony2 -更改迁移目录

Symfony2 -更改迁移目录
EN

Stack Overflow用户
提问于 2013-06-12 21:21:32
回答 2查看 6.9K关注 0票数 5

如何更改config.yml中的默认迁移目录?现在,我正在使用两个具有不同数据库连接的捆绑包,我想创建迁移文件并将它们存储在不同的目录中,以使用原理: migrations :migrate--em=依赖于捆绑包的任何函数。

例如:

代码语言:javascript
复制
doctrine:migrate:diff --em=whatever #creating a version file in the DoctrineMigrationsWhatever directory

php app/console doctrine:migrations:status --em=whatever # shows only the version files, that belong to the bundle
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-06-12 21:34:15

如果您将为第二个连接/包创建单独的实体管理器,您将在DoctrineMigrations目录中获得另一个目录。例如:

代码语言:javascript
复制
app/
    DoctrineMigrations/
        entityManager1/
        entityManager2/

如果您希望将所有迁移放到另一个目录中,可以在config.yml中进行设置:

代码语言:javascript
复制
doctrine_migrations:
    dir_name: '%kernel.root_dir%/../Acme/CommonBundle/DoctrineMigrations'
    namespace: 'Acme\CommonBundle\DoctrineMigrations'

如果你想做一些更复杂的事情,比如把从em1到dir1的迁移放到bundle1中,把从em2到dir2的迁移放到bundle2中,你需要另外两个配置文件,在这两个文件中,你将为特定的包指定目录:

http://docs.doctrine-project.org/projects/doctrine-migrations/en/latest/reference/introduction.html#configuration

然后像这样运行迁移:

代码语言:javascript
复制
doctrine:migrations:status --em=em1 --configuration=./path/to/bundle1/Resources/config/migrations.yml
doctrine:migrations:status --em=em2 --configuration=./path/to/bundle2/Resources/config/migrations.yml

作者:https://github.com/doctrine/DoctrineMigrationsBundle/pull/46

migrations.yml文件应如下所示:

代码语言:javascript
复制
name: Doctrine Postgres Migrations  
migrations_namespace: Application\Migrations  
table_name: migration_versions  
migrations_directory: PostgreSqlMigrations  
票数 13
EN

Stack Overflow用户

发布于 2019-05-31 02:32:15

对于Symfony 4,推荐的方法是改用%kernel.project_dir%,并将其放在由App\命名的src/文件夹中

代码语言:javascript
复制
doctrine_migrations:
    dir_name: '%kernel.project_dir%/src/DoctrineMigrations'
    namespace: 'App\DoctrineMigrations'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17066670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档