繁体   English   中英

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

[英]Symfony2 Import entities from existing database with Doctrine

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

然后在此处搜索,我发现这里使用symfony2和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$

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

$ php app/console doctrine:mapping:convert annotation ./src
$ php app/console doctrine:generate:entities AcmeBlogBundle

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

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$

有什么建议吗?

试试:

# 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 

此处有更多文档:

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

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

PS。 最好的做法是将捆绑包OrganizerScheduleBundle(看起来是大写字母)以Organizer作为公司名称,因此在developer / company name文件夹中将有所有捆绑包。

如果您正在使用symfony 3并想使用注释,我使用了这个:

php bin/console doctrine:mapping:import --force AcmeBlogBundle annotation

这将生成您所需的全部内容,而无需使用以下教义:mapping:convert

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM