[CDBI] Primary key declarations on non-primary key columns fails
dbasch at yahoo.com
Tue Aug 22 01:55:40 BST 2006
I spend several hours tracking down this error and I thought I would submit it to this list before
submitting a feature request to CPAN.
For this example I am using Mysql v5.0 and Class::DBI v3.0.15
If you declare a column as a primary key with Class::DBI like this:
Music::CD->columns(Primary => qw/pk1 pk2/);
and the column is not declared as a primary key in the database schema then you will get this
rather unhelpful error:
Can't insert new Database::Table: Can't get last insert id at /usr/local/lib/foo.pm line 180
As soon as you declare the column as primary in the database schema the error disappears.
It seems like Class::DBI should do an idiot check (yes, I am definitely the idiot on this one) to
ensure that the column really is a primary key column in the database schema.
The primary_key_info method of the DBI database handle object should return that information. I am
not sure where this would best fit in the Class::DBI package but my guess would be in the
add_group method of the Class::DBI::ColumnGrouper module.
Anyways, let me know what you think and if I should submit this as a feature request.
Thanks for the help,
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
More information about the ClassDBI