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?

4
  • 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. Commented May 13, 2014 at 11:14
  • When execute php app/console doctrine:schema:update --force a error appear: No Metadata Classes to process. Commented May 13, 2014 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. Commented May 13, 2014 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 Commented May 13, 2014 at 13:22

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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.
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).
I checked this, I program with eclipse symfony plugin and I see a error in doctrine-mapping.xsd ':cos-nonambig: WC[##other:"doctrine-project.org/schemas/orm/doctrine-mapping"] and WC[##other:"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?
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.
Thank you @Andrej Mohar I solved with the Cerad comment
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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.