Symfony2 - Doctrine2 - MySql:复合FK和PK(Symfony2 - Doctrine2 - MySql: Composite FK and PK)
我正在使用Symfony2,Doctrine2和MySql。 我有两张桌子:评论和主题。 Review有一个复合PK(idReview和idHotel)。 主题只有一个PK(idTopic)。 我想在这两个表之间创建多对多关系。 结果表(例如,Review_Topic)必须具有由三个FK组成的复合PK(idReview,idHotel,idTopic)。 当我更新架构时,MySql给出了错误1005,因为FK(idReview,idHotel)而无法创建表,errno 150。遵循包含多对多关系的Review和Topic的Yaml配置:
Review: ... manyToMany: topics: targetEntity: Topic inversedBy: reviews joinTable: name: reviews_topics joinColumns: idReview: referencedColumnName: idReview idHotel: referencedColumnName: idHotel inverseJoinColumns: topic_id: referencedColumnName: idTopic fields: score: type: integer Topic: ... manyToMany: reviews: targetEntity: Review mappedBy: topics
非常感谢您的帮助。
I am using Symfony2, Doctrine2 and MySql. I have two tables: Review and Topic. Review has a composite PK (idReview and idHotel). Topic has only one PK (idTopic). I want to create a many-to-many relation between these two tables. The join table resulting (e.g Review_Topic) must have a composite PK (idReview, idHotel, idTopic) made of the three FK. When I update the schema, MySql gives me the error 1005, can't create table, errno 150 because of the FK (idReview, idHotel).Following the Yaml configuration of Review and Topic including the many-to-many relation:
Review: ... manyToMany: topics: targetEntity: Topic inversedBy: reviews joinTable: name: reviews_topics joinColumns: idReview: referencedColumnName: idReview idHotel: referencedColumnName: idHotel inverseJoinColumns: topic_id: referencedColumnName: idTopic fields: score: type: integer Topic: ... manyToMany: reviews: targetEntity: Review mappedBy: topics
Thanks a lot for any help.
原文: