2

I am a beginner with symfony. I have tried to follow the official documentation http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html to import a entities from MySQL to a symfony2 project in a Debian testing box. but I didn't succeeded.

Then searching here and there I have found this Generating a single Entity from existing database using symfony2 and doctrine here, but I cant make it work, my console: "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$

So far so good, but now "you can ask Doctrine to build related entity classes by executing the following two commands.

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

but when I do it the first one doesn't work for me:

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$

Any suggestion?

Community
  • 1
  • 1
Abel
  • 538
  • 5
  • 8
  • 28

2 Answers2

6

Try with:

# 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 

More docs here:

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

Not all will be imported (the doc says 70-80% but in my opinion is less).

PS. A best pratice is to call the bundle OrganizerScheduleBundle (look uppercase letters) with organizer as company name, so inside the developer/company name folder there will be all the bundles.

M. Foti
  • 3,156
  • 2
  • 16
  • 14
  • Hi; I have solved it a while ago, but the true now is that I do not really remember how! The next time I ask I will be more accountable for interaction with the community Thank you guys and I am sorry about forgetting about this post, it will not happen again. – Abel Sep 23 '13 at 10:20
1

If you are using symfony 3 and wanna use the annotations, i used this:

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

This generate all you need, without needing the doctrine:mapping:convert