开发者

Couldn't get last insert identifier - Doctrine with mysql views

I have one table and one view (create view as select * from table). I am using php, mysql and doctrine 1.2 ORM.

If I insert data in table everything works as expected but when I try to insert data into view I get the following error:

Couldn't get last insert identifier. 

Any idea how to fix this? (I really need to use views, so inserting into main table would not be OK)

Whole error:

Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'Couldn't get last insert identifier.' in C:\wamp\www\www\class\lib\doctrine_1.2\lib\Doctrine\Connection\UnitOfWork.php:941 Stack trace: C:\wamp\www\bicikel-www\class\lib\doctrine_1.2\lib\Doctrine\Connection\UnitOfWork.php(636): Doctrine_Connection_UnitOfWork->_assignIdentifier(Object(Event)) C:\wamp\www\www\class\lib\doctrine_1.2\lib\Doctrine\Connection\UnitOfWork.php(566): Doctrine_Connection_UnitOfWork->processSingleInsert(Object(Event)) C:\wamp\www\www\class\lib\doctrine_1.2\lib\Doctrine\Connection\UnitOfWork.php(81): Doctrine_Connection_UnitOfWork->insert(Object(Event)) C:\wamp\www\www\class\l开发者_如何学编程ib\doctrine_1.2\lib\Doctrine\Record.php(1705): Doctrine_Connection_UnitOfWork->saveGraph(Object(Event)) C:\wamp\www\www\opravila\migajznami_spider.php(97): Doctrine_Record->save() {main} thrown in C:\wamp\www\www\class\lib\doctrine_1.2\lib\Doctrine\Connection\UnitOfWork.php on line 941


May be you haven't primary key with autoincrement . Doctrine is looking for autoincrement property.


I have updated Doctrine files and now it works.

I changed file: Doctrine\Connection\UnitOfWork.php, line 936 I added some code in else block:

} else {
    $id = $record->$identifier;
    if(!$id){    // added
    $id = $this->conn->sequence->lastInsertId();    // added
    } // added
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜