【发布时间】:2012-06-15 21:24:10
【问题描述】:
通过 Symfony 原则更新表时,我偶尔会收到“违反完整性约束:1062 Duplicate entry ... for key 'PRIMARY'”错误。该表是使用相应的历史表创建的。错误不是来自更新表本身,而是来自在历史表中插入记录。我正在使用 Symfony 1.4,学说 1.2。知道是什么原因造成的吗?谢谢。
$this->computer = $computerTable->findOneByMacAddress($this->props['mac_address']);
$this->computer->ip_address = $this->ip;
$this->computer->setLastCheckinAt(date('Y-m-d H:i:s')) ;
$this->computer->save();
schema.yml
Computer:
actAs:
Timestampable: ~
History:
className: %CLASS%History
auditLog: true
deleteVersions: false
cascadeDelete: false
columns:
mac_address: { type: string(13), notnull: true, }
last_checkin_at: { type: string(60), }
ip_address: { type: string(40), fixed: false, notnull: false, }
...
【问题讨论】:
-
发布生成错误的代码以及架构的相关部分。另外,您是在尝试手动更新历史记录表,还是在尝试自动更新时抛出异常?
-
$this->computer = $computerTable->findOneByMacaddress($this->props['mac_address']);
-
嗯?更新您的问题,并且不会进行任何保存,因此它不会产生违反约束的情况...您需要插入、更新或删除才能发生这种情况...
-
尝试自动更新历史表时抛出异常。
-
原代码太长,这里就不贴了。我确定返回了正确的记录。该错误是由于将记录保存在历史表中引起的。顺便说一句,这是在负载平衡的环境中。