2

Symfony doctrine を使用してテーブルを更新すると、「整合性制約違反: 1062 エントリが重複しています ... キー 'PRIMARY' の場合」というエラーが発生することがあります。テーブルは、対応する履歴テーブルで作成されます。エラーは、テーブル自体の更新によるものではなく、履歴テーブルへのレコードの挿入によるものです。私は Symfony 1.4、doctrine 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, }
    ...
4

1 に答える 1

2

ほとんどfindOneByMacAddressの場合、既存のレコードが見つからず、データベースに保存している空の列のMACアドレスがあります。

次のようなものを試してください。

if(!$this->computer = $computerTable->findOneByMacAddress($this->props['mac_address']))
{
   $this->computer = new Computer();
}
/*do logic here*/
$this->computer->save();
于 2012-06-15T22:17:53.607 に答える