【问题标题】:Doctrine - PHP Fatal error: 'Couldn't get last insert identifier.'Doctrine - PHP 致命错误:“无法获取最后一个插入标识符。”
【发布时间】:2011-06-05 19:12:38
【问题描述】:

我对 Doctrine 有一点问题。我收到以下错误:

PHP Fatal error:  Uncaught exception 'Doctrine_Connection_Exception' with message 'Couldn't get last insert identifier.'

我查看了这篇帖子,Doctrine Problem: Couldn't get last insert identifier,这很有帮助,但我的问题有点不同。

我在不应具有 auto_increment 主键的表上收到此错误。我的设置如下:

Event:
  id:int, PK, auto_increment

User
  id: int, PK, auto_increment

UserEvent:
  user_id:int, PK
  event_id: int, PK

我在插入 UserEvent 时遇到问题。所以流程是,我在 Event 中插入一条记录,然后在 User 中插入一条记录,然后在 UserEvent 中插入一条记录。

有趣的是,它插入了所有这 3 个罚款。但是在插入最后一个(UserEvent)之后,它会抛出该错误。

有什么想法吗?

【问题讨论】:

  • 有人对此有什么建议吗?

标签: orm doctrine


【解决方案1】:

弄明白了——在 YML 模式中,UserEvent.user_id 和 UserEvent.event_id 没有属性——primary: true

一旦我这样做并重新生成模型,错误就消失了

【讨论】:

    猜你喜欢
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多