Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create tables with entities - Doctrine Symfony2

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?

like image 912
Alex Avatar asked May 13 '14 11:05

Alex


2 Answers

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.

like image 68
Andrej Mohar Avatar answered Oct 24 '22 02:10

Andrej Mohar


I recommend you to use migration mechanism. There is great tool for the Symfony (DoctrineMigrationsBundle)

  1. Create an entity class with all necessary properties;
  2. Create getters / setters( using IDE or app/console doctrine:generate:entities YourBundle:Entity);
  3. Create migration file(app/console doctrin:migration:diff);
  4. Use the migration(app/console docttrin:migration:migrate);
like image 42
Dick D. Russell Avatar answered Oct 24 '22 01:10

Dick D. Russell