DDC-2646: Column name id referenced for relation from EntityB towards EntityA does not exist. #3318

Closed
opened 2026-01-22 14:17:57 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 2, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user gog:

/****
 * @ORM\Entity()
 */
class EntityA {

    /****
     * @ORM\Id
     * @ORM\Column(type="string", length=255)
     * @var string
     */
    protected $name;

    /****
     * @ORM\ManyToMany(targetEntity="EntityB", mappedBy="as")
     */
    protected $bs;
}
/****
 * @ORM\Entity()
 */
class EntityB {

    /****
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @var string
     */
    protected $id;

    /****
     * @ORM\ManyToMany(targetEntity="EntityA", inversedBy="bs")
     */
    protected $as;
}

Trying to generate the schema throws an exception:

```Column nameid referenced for relation from EntityB towards EntityA does not exist.


If I change the name of the @Id field in EntityA from $name to $id, everything works.

I have tried adding @JoinColumn definition to EntityB like this:

/****
 * @ORM\ManyToMany(targetEntity="EntityA", mappedBy="as")
 * @ORM\JoinTable(name="a*to_b", joinColumns={@ORM\JoinColumn(name="entitya*name", referencedColumnName="name")}
 * )
 */
protected $bs;

But that just changes the name of the field in the error message:

```Column name `name` referenced for relation from EntityB towards EntityA does not exist.
Originally created by @doctrinebot on GitHub (Sep 2, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user gog: ``` /**** * @ORM\Entity() */ class EntityA { /**** * @ORM\Id * @ORM\Column(type="string", length=255) * @var string */ protected $name; /**** * @ORM\ManyToMany(targetEntity="EntityB", mappedBy="as") */ protected $bs; } ``` ``` /**** * @ORM\Entity() */ class EntityB { /**** * @ORM\Id * @ORM\Column(type="integer") * @var string */ protected $id; /**** * @ORM\ManyToMany(targetEntity="EntityA", inversedBy="bs") */ protected $as; } ``` Trying to generate the schema throws an exception: ```Column name`id` referenced for relation from EntityB towards EntityA does not exist. ``` If I change the name of the @Id field in EntityA from $name to $id, everything works. I have tried adding @JoinColumn definition to EntityB like this: ``` ``` /**** * @ORM\ManyToMany(targetEntity="EntityA", mappedBy="as") * @ORM\JoinTable(name="a*to_b", joinColumns={@ORM\JoinColumn(name="entitya*name", referencedColumnName="name")} * ) */ protected $bs; ``` `````` But that just changes the name of the field in the error message: ```Column name `name` referenced for relation from EntityB towards EntityA does not exist. ``````
admin added the Bug label 2026-01-22 14:17:57 +01:00
admin closed this issue 2026-01-22 14:17:57 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 2, 2013):

Comment created by gog:

Finally found the issue, when I moved the definition of the JoinTable to EntityA it all worked as expected.

@doctrinebot commented on GitHub (Sep 2, 2013): Comment created by gog: Finally found the issue, when I moved the definition of the JoinTable to EntityA it all worked as expected.
Author
Owner

@doctrinebot commented on GitHub (Sep 2, 2013):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Sep 2, 2013): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3318