首页 文章

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

提问于
浏览
2

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

然后在这里和那里搜索我在这里找到了这个Generating a single Entity from existing database using symfony2 and doctrine,但我不能让它工作,我的控制台:"ask Doctrine to introspect the database and generate the corresponding metadata files"

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$

有什么建议吗?

2 回答

  • 6

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

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

    这将生成您需要的所有内容,而无需使用doctrine:mapping:convert

  • 1

    试试:

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

相关问题