8

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Alex
  • 93
  • 1
  • 1
  • 5
  • You can use `php app/console doctrine:database:create` to create the database and then `php app/console doctrine:schema:update --force`. You can read more in the [documentation](http://symfony.com/doc/current/book/doctrine.html). – Faery May 13 '14 at 11:14
  • When execute php app/console doctrine:schema:update --force a error appear: No Metadata Classes to process. – Alex May 13 '14 at 11:16
  • You are mapping your your classes using annotations? Make sure you don't have any orm files hanging around under Resources/config/doctrine. – Cerad May 13 '14 at 13:03
  • @Cerad Yes I had a file in Resources/config/doctrine, when I deleted it I could generate the tables! Thank you very much – Alex May 13 '14 at 13:22

2 Answers2

10

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.

Andrej Mohar
  • 966
  • 8
  • 20
  • When execute php app/console doctrine:schema:update --force and php app/console doctrine:schema:update --dump-sql appear a error No Metadata Classes to process When execute p hp app/console doctrine:generate:entities Acc\ApssBundle\Entity appears [RuntimeException] Namespace "Acc\ApssBundle\Entity" does not contain any mapped entities. – Alex May 13 '14 at 11:41
  • That happened to me several times. Check that your namespace definition is correct according to the php file path. Check that you have added `@ORM\Entity` annotation above the entity class definition. Finally check if you're having the correct path in the `doctrine:generate:entities` command. Note that you also have to include the folder above the bundle in the path, afaik (example: `php app/console doctrine:generate:entities App\MainBundle\Entity`). – Andrej Mohar May 13 '14 at 11:54
  • I checked this, I program with eclipse symfony plugin and I see a error in doctrine-mapping.xsd ':cos-nonambig: WC[##other:"http://doctrine-project.org/schemas/orm/doctrine-mapping"] and WC[##other:"http://doctrine- project.org/schemas/orm/doctrine-mapping"] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.' Ahy idea? – Alex May 13 '14 at 13:05
  • Can you update your question with the code for your entities, especially the code with the doctrine entity annotations? I don't know if I'll be able to help, but someone surely will. Also, please paste the exact symfony command you're trying to execute. – Andrej Mohar May 13 '14 at 13:30
  • Thank you @Andrej Mohar I solved with the Cerad comment – Alex May 13 '14 at 13:35
1

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);