Unable to create table in MySQL using Doctrine and Symfony2 Unable to create table in MySQL using Doctrine and Symfony2 symfony symfony

Unable to create table in MySQL using Doctrine and Symfony2


I've had a similar problem. Most likely you have two entities named Category inside different Bundles. For instance:

src/Acme/SomeBundle/Entity/Product.phpsrc/Acme/OtherBundle/Entity/Product.php

Comment one of these files and retry the console command.


I was getting this problem from a conflict with join table defined in an association class annotation and a join table defined in a ManyToMany annotation.

The mapping definitions in two entities with a direct ManytoMany relationship appeared to result in the automatic creation of the join table using the 'joinTable' annotation. However the join table was already defined by an annotation in its underlying entity class and I wanted it to use this association entity class's own field definitions so as to extend the join table with additional custom fields.

The explanation and solution was thanks to this post in the forum 'Doctrine Annotation Question'. This post draws attention to the Doctrine documentation regarding ManyToMany Uni-directional relationships. Look at the note regarding the approach of using an 'association entity class' thus replacing the many-to-many annotation mapping directly between two main entity classes with a one-to-many annotation in the main entity classes and two 'many-to-one' annotations in the Associative Entity class. There is an example provided in this forum post Association models with extra fields:

public class Person{    /**      * @OneToMany(targetEntity="AssignedItems", mappedBy="person")     */    private $assignedItems;}public class Items{    /**     * @OneToMany(targetEntity="AssignedItems", mappedBy="item")     */    private $assignedPeople;}public class AssignedItems{    /**      * @ManyToOne(targetEntity="Person")     * @JoinColumn(name="person_id", referencedColumnName="id")     */    private $person;    /**      * @ManyToOne(targetEntity="Item")     * @JoinColumn(name="item_id", referencedColumnName="id")     */    private $item;}


I got this error when editing my Product.orm.yml file.

I added a new manyToMany relation with a Category entity, and made a mistake on the joinTable line :

manyToMany:  categories:    targetEntity: Acme\ProductBundle\Entity\Category    inversedBy: products    joinTable:      name: Product  # My mistake: joinTable should be something like ProductCategory    [...]

Indeed it's a silly error, I share anyway.