Creating Entity Tables - Doctrine Symfony2

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

What is the command to create these classes as Doctrine objects and Mysql tables?

+7
symfony doctrine entities
source share
2 answers

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

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

+8
source share

I recommend using the migration mechanism. Symfony has a great tool ( DoctrineMigrationsBundle )

  • Create an entity class with all the necessary properties;
  • Create getters / setters (using the IDE or the doctrine app / console: generate: entity YourBundle: Entity);
  • Create a migration file (app / console doctrin: migration: diff);
  • Use migration (docttrin app / console: migration: migration);
+1
source share

All Articles