教义2.0 |创建数据库 |外键是否唯一
- 我正在使用 Doctrine 2.0 和最新版本的 MySQL 以及 PHP 5.3.5
- 我目前使用 PHP 映射来创建我的数据库。
我有一个模型(Event),它与另一个模型(EventInvitations)具有 one2one 关系 - 这可能应该是 one2many,但让我们继续。
我当前的 EventInvitations 映射在 eventid 和 userid 上有一个 UniqueConstraint。
我的 EventInivitation 也有一个 OneToOne Join 事件,这是
我运行时的外键:“doctrine.php orm:schema-tool:update --force” Doctrine 将成功创建我的唯一索引,但它似乎也会创建另一个 Uniq 索引它有一个类似 Uniq_AHJHAUSH7J 的键名,但位于 EventId 字段上。
问题是我不希望外键创建唯一字段。有没有办法告诉 Doctrine 不要为外键创建唯一索引?
- I'm using Doctrine 2.0 and the latest version of MySQL aswell as PHP 5.3.5
- I currently use PHP mapping to create my database.
I have a model (Event) which has a one2one relationship with another model (EventInvitations) - this should probably be one2many but lets move on from that.
My current mapping for EventInvitations has a UniqueConstraint on an eventid and a userid.
My EventInivitation also has a OneToOne Join on Event, this is a Foreign Key
when i run: "doctrine.php orm:schema-tool:update --force" Doctrine will successfully create my Unique index but it also seems to create another Uniq index which has a key name like Uniq_AHJHAUSH7J but on EventId field.
The problem is that i dont want the Foreign Key to create a Unique Field. Is there a way for me to tell Doctrine not to create the Unique index for the foreign key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一对一关系意味着唯一性。这意味着对于给定的 EventInvitation,有一个 Event,反之亦然。
您可能希望多个 EventInvitation 与一个 Event 关联,在这种情况下,关系应该是 ManyToOne(从 EventInvitation 的角度来看);因此,您将能够拥有事件的外键,而无需唯一索引。
A OneToOne relationship implies uniqueness. It means that for a given EventInvitation there is one Event, and vice-versa.
You probably want several EventInvitations to be associated with one Event, and in that case the relationship should be ManyToOne (from the perspective of EventInvitation); as such you will be able to have the foreign key to an Event without the unique index.