Doctrine orm 多对多连接错误

Doctrine orm 多对多连接错误,doctrine-orm,zend-framework2,Doctrine Orm,Zend Framework2,我正在尝试使用原则2在ZF2中创建从产品到类别表的多对多连接 在我的分类中,我有实体 /** * @var \Doctrine\ORM\PersistentCollection * * @ORM\ManyToMany(targetEntity="Application\Entity\Products", inversedBy="categories") * @ORM\JoinTable(name="product_to_category", *

我正在尝试使用原则2在ZF2中创建从产品到类别表的多对多连接

在我的分类中,我有实体

/**
     * @var \Doctrine\ORM\PersistentCollection
     * 
     * @ORM\ManyToMany(targetEntity="Application\Entity\Products", inversedBy="categories")
     * @ORM\JoinTable(name="product_to_category",
     *      joinColumns={@ORM\joinColumn(name="category_id", referencedColumnName="category_id")},
     *      inverseJoinColumns={@ORM\joinColumn(name="product_id", referencedColumnName="product_id")}
     * )
     */
    private $products;
/**
     * @var Doctrine\ORM\PersistentCollection
     *
     * @ORM\ManyToMany(targetEntity="Application\Entity\Categories", mappedBy="products")
     */
    private $categories;
在我的产品实体中,我有

/**
     * @var \Doctrine\ORM\PersistentCollection
     * 
     * @ORM\ManyToMany(targetEntity="Application\Entity\Products", inversedBy="categories")
     * @ORM\JoinTable(name="product_to_category",
     *      joinColumns={@ORM\joinColumn(name="category_id", referencedColumnName="category_id")},
     *      inverseJoinColumns={@ORM\joinColumn(name="product_id", referencedColumnName="product_id")}
     * )
     */
    private $products;
/**
     * @var Doctrine\ORM\PersistentCollection
     *
     * @ORM\ManyToMany(targetEntity="Application\Entity\Categories", mappedBy="products")
     */
    private $categories;
但我不断收到错误致命错误:未捕获异常“条令\ORM\Mapping\MappingException”,消息为“列类别id必须映射到类应用程序\Entity\Categories中的字段,因为它被另一个类的联接列引用。”在C:\Users\User\Documents\My中当我尝试延迟加载数据时,第328行的Webs\freedomsnew\vendor\doctor\orm\lib\doctor\orm\Mapping\MappingException.php

我不确定是什么错误试图告诉我,我看不到任何错误

请有人给我指一下正确的方向


非常感谢。

您尚未发布这两个实体的标识字段。错误表明
Category
表没有名为
Category\u id
的列,因为它是PK。默认情况下,您应该使用
id
作为实体的id(这将导致db表上的列名为
id
);然后将
referenceColumnName
更新为
id
。谢谢@AlexP的回复,我刚刚发现了问题。类别id在数据库中拼写为类别id。我还使用了“php./vendor/doctor/doctor module/bin/doctor module orm validate schema”来提供有关错误的更多信息。错误表明
Category
表没有名为
Category\u id
的列,因为它是PK。默认情况下,您应该使用
id
作为实体的id(这将导致db表上的列名为
id
);然后将
referenceColumnName
更新为
id
。谢谢@AlexP的回复,我刚刚发现了问题。类别id在数据库中拼写为类别id。我还使用了“php./vendor/doctor/doctor module/bin/doctor module orm validate schema”来提供有关错误的更多信息。错误表明
Category
表没有名为
Category\u id
的列,因为它是PK。默认情况下,您应该使用
id
作为实体的id(这将导致db表上的列名为
id
);然后将
referenceColumnName
更新为
id
。谢谢@AlexP的回复,我刚刚发现了问题。类别id在数据库中拼写为类别id。我还使用了“php./vendor/doctrine/doctrine模块/bin/doctrine模块orm验证模式”来提供有关错误的更多信息。