How to specify a database connection to Doctrine fixtures?

血红的双手。 提交于 2020-01-06 06:34:12

问题


I am using Symfony 4 and I have a CI pipeline to deploy my app to a dev server. Using Doctrine features, I can execute the database migrations using a --db-configuration option:

./bin/console doctrine:migrations:migrate \
    --allow-no-migration \
    --db-configuration=dev_conn.php \
    --no-interaction

I would like to load the fixtures in the same manner, but the --db-configuration option isn't listed in help for the doctrine:fixtures:load command.

  • Is there an "hidden" option to this command which could do this ?
  • If not, what would be the best workaround to be able to load fixtures on my remote server ?

回答1:


Create another Entity Manager with credentials of the remote server (using another environment variable) as described in the documentation and pass the option—em=your_second_manager in your fixtures command.




回答2:


you can define a symfony service for each of your entitymanagers and inject the desired one explicitly into your fixture class afterwards. the fixture would then be a service as well.



来源:https://stackoverflow.com/questions/56419241/how-to-specify-a-database-connection-to-doctrine-fixtures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!