2010-04-12 4 views
6

Gdy próbuję zapisać dane do mojego modelu Nauki rzuca ten wyjątek:Doktryna Problem: Nie można uzyskać identyfikator ostatni insert

Message: Couldn't get last insert identifier. 

Moja tabela kod konfiguracja jest:

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

Proszę o pomoc. Dzięki.

Odpowiedz

14

Upewnić się, że kolumna w twojej bazie danych jest ustawione jako auto_increment. Wygląda na to, że klasa Doctrine obsługuje ją jako auto_increment, ale nie jest ustawiona jako taka w DB.

+2

Chciałbym móc to powtórzyć więcej razy. Właśnie popełniłeś gnarly bug z 10-minutową poprawką. –

1

Ten pracował dla mnie:

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

miały takie same parametry jak wcześniej, ten sam błąd zbyt.

EDIT: Niedawno znalazłem o dodanie „AUTO_INCREMENT” do definicji kolumny PK, a teraz zachowuje się tak samo jak w danym polu ID obsługiwane przez Doctrine z dowolną nazwą wybiorę

2

Dla mnie problemem był paramater 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, 
     )); 
Powiązane problemy