Symfony2使用Doctrine从现有数据库导入实体

Abe*_*bel 2 php mysql doctrine symfony doctrine-orm

我是symfony的初学者.我试图按照官方文档http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html将实体从MySQL导入Debian测试框中的symfony2项目.但我没有成功.

然后在这里和那里搜索我发现这里使用symfony2和doctrine现有数据库中生成一个单独的实体,但我无法使它工作,我的控制台:"要求Doctrine内省数据库并生成相应的元数据文件"

root@khs01wxl001:/var/www/organizer$ php app/console doctrine:mapping:import --force organizerscheduleBundle php
Importing mapping information from "default" entity manager
  > writing /var/www/organizer/src/organizer/scheduleBundle/Resources/config/doctrine/Dept.orm.php
  > writing /var/www/organizer/src/organizer/scheduleBundle/Resources/config/doctrine/Desg.orm.php
  > writing /var/www/organizer/src/organizer/scheduleBundle/Resources/config/doctrine/Dir.orm.php
  > writing /var/www/organizer/src/organizer/scheduleBundle/Resources/config/doctrine/Schedule.orm.php
  > writing /var/www/organizer/src/organizer/scheduleBundle/Resources/config/doctrine/Username.orm.php
  > writing /var/www/organizer/src/organizer/scheduleBundle/Resources/config/doctrine/Userrole.orm.php
root@khs01wxl001:/var/www/organizer$
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利,但现在"你可以通过执行以下两个命令来让Doctrine构建相关的实体类.

$ php app/console doctrine:mapping:convert annotation ./src
$ php app/console doctrine:generate:entities AcmeBlogBundle
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,第一个对我不起作用:

root@khs01wxl001:/var/www/organizer$ php app/console doctrine:mapping:convert annotation ./src/organizer/scheduleBundle/Resources/config/doctrine/
No Metadata Classes to process.
root@khs01wxl001:/var/www/organizer$
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

小智 6

试试:

# write the structure to annotation file (I prefear to use YML instead annotation but should be the same) 
$ php app/console doctrine:mapping:convert annotation ./src/organizer/scheduleBundle/Resources/config/doctrine/metadata/orm --from-database --force

# Import the structure
$ php app/console doctrine:mapping:import organizerscheduleBundle annotation

# Generate Entities file class
$ php app/console doctrine:generate:entities organizerscheduleBundle 
Run Code Online (Sandbox Code Playgroud)

更多文档:

http://docs.doctrine-project.org/en/2.0.x/reference/tools.html#reverse-engineering

并非所有都会被导入(文档说70-80%,但在我看来更少).

PS.最好的方法是使用组织者作为公司名称调用BundizerScheduleBundle(看大写字母),因此在开发人员/公司名称文件夹中将包含所有捆绑包.