zby has asked for the wisdom of the Perl Monks concerning the following question:
The primary key column is of the 'serial' type so it should be set from the implicite sequence here - but still I get following error:use lib 'lib'; use Party::M::CDBI::Declaration; my $a = Party::M::CDBI::Declaration->create({freetext => 'aaasdds'});
Interestingly when I run in psql I omit the 'id' in the values the statement works:Can't insert new Party::M::CDBI::Declaration: DBD::Pg::st execute fail +ed: ERROR: null value in column "id" violates not-null constraint [for Statement "INSERT INTO declaration (freetext, id) VALUES (?, ?) " with ParamValues: ] at /usr/local/share/perl/5.8.4/DBIx/ContextualFe +tch.pm line 51. at a.pl line 6
INSERT INTO declaration (freetext) VALUES ('aaasdds');
package Party::M::CDBI; use strict; use base 'Class::DBI'; __PACKAGE__->connection('dbi:Pg:dbname=party', 'zby', '***', { AutoCom +mit => 1 , RaiseError=>1}); package Party::M::CDBI::Declaration; use base Party::M::CDBI; use strict; __PACKAGE__->table('declaration'); __PACKAGE__->columns(All => qw/id usr place freetext cdate/); __PACKAGE__->has_a(usr => 'Party::M::CDBI::Usr');
create table declaration( id serial primary key, usr integer CONSTRAINT declaration_usr references usr(id) on delete ca +scade, place varchar(50), freetext text, cdate timestamp default CURRENT_TIMESTAMP );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class::DBI and 'serial' columns in PostgreSQL
by davidrw (Prior) on Aug 16, 2005 at 16:49 UTC | |
by zby (Vicar) on Aug 16, 2005 at 19:41 UTC |