tags:

views:

718

answers:

2

When i try to save data to my model Doctrine throws this exception:

Message: Couldn't get last insert identifier. 

My table setup code is:

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

Please help. Thanks.

+1  A: 

This worked for me:

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

Had the same parameters as you previously, same error too.

EDIT: I recently found about adding "auto_increment" to the PK column definition and now I it behaves the same as any given ID field handled by Doctrine with whatever name I choose

PasadenaGuy
A: 

Check to make sure that the column in your database is set up as auto_increment. It looks like the Doctrine class is handling it as an auto_increment but it's not set up as such in the DB.

Thomas