Create tables with entities - Doctrine Symfony2

Alex picture Alex · May 13, 2014 · Viewed 26.8k times · Source

I created several classes without using the php command php app/console doctrine:generate:entity, directly I created and mapping the php classes in the folder MyBundle/Entity.

What is the command to generate these classes as Doctrine entities and Mysql tables?

Answer

Andrej Mohar picture Andrej Mohar · May 13, 2014

Assuming you have all the needed annotations and correct getters / setters in your php files, it should be enough to call php app/console doctrine:schema:update --force. For preview purposes ypu can use php app/console doctrine:schema:update --dump-sql. That will show you the sql which will be executed.

If you only have annotated properties without getters / setters (so you have created the php files, added properties which you want as columns and added their respective annotations), first use php app/console doctrine:generate:entities MyBundle/Entity. This will create the getters/setters for you. Check here for additional information.