2010-04-12 32 views
6

當我嘗試將數據保存到我的模型學說拋出此異常:主義問題:無法獲得最後插入標識

Message: Couldn't get last insert identifier. 

我的表設置代碼是:

$this->hasColumn('id', 'integer', 4, array(
     'type' => 'integer', 
     'length' => 4, 
     'fixed' => false, 
     'unsigned' => false, 
     'primary' => true, 
     'autoincrement' => true, 
     )); 

請幫助。謝謝。

回答

14

檢查處理任何給定的ID字段,以確保該列在你的數據庫中設置爲auto_increment。它看起來像Doctrine類正在處理它作爲一個auto_increment,但它沒有在數據庫中這樣設置。

+2

我希望我可以比這更多次。你只是做了一個粗糙的bug有10分鐘的修復。 – 2011-05-06 16:44:39

1

這爲我工作:

$this->hasColumn('cd_fabricante', 'integer', 4, array(
      'type' => 'integer', 
      'length' => 4, 
      'unsigned' => true, 
      'primary' => true, 
      'auto_increment' => true, 
)); 

有同樣的參數,你以前,同樣的錯誤了。

編輯:我最近發現關於加入「AUTO_INCREMENT」的PK列定義,現在我把它的行爲相同。通過主義與任何名義,我選擇

2

對我來說,問題是default參數。

 $this->hasColumn('inscription_id', 'integer', 4, array(
     'type' => 'integer', 
     'length' => 4, 
     'fixed' => false, 
     'unsigned' => false, 
     'primary' => true, 
//  'default' => '0', !!! get "couldn't get last inserted identifier doctrine" 
     'notnull' => true, 
     'autoincrement' => true, 
     ));