[Dbix-class] bug with find_or_new and update_or_insert, for
postgres DB
Jess Robinson
castaway at desert-island.me.uk
Mon Jan 7 09:43:49 GMT 2008
On Sun, 6 Jan 2008, Patrick Weemeeuw wrote:
> | create table article (
> | artId integer NOT NULL DEFAULT nextval('article_artid_seq'),
> | day char(8) NOT NULL,
> | seqnr integer NOT NULL,
> | visibility char(1) NOT NULL CHECK ( visibility = 'P' OR visibility = 'R' OR visibility = '' ),
> | title varchar(100) NOT NULL, -- ftext
> | body text NOT NULL, -- ftext
> | UNIQUE (day,seqnr),
> | UNIQUE (artid)
> | );
> | my $art = $schema->resultset('Article')->find_or_new( { artid => undef } );
> | $ perl -I ../lib testme3.pl
> | 0.08008
> | DBIx::Class::Row::update_or_insert(): DBI Exception: DBD::Pg::st execute failed: ERROR: null value in column "artid" violates not-null constraint
> | [for Statement "INSERT INTO article (artid, body, day, seqnr, title, visibility) VALUES (?, ?, ?, ?, ?, ?)" with ParamValues: 6='P', 4='3', 1=undef, 3='20022222', 2='bbb', 5='ttt'] at testme3.pl line 30
>
Why are you explicitly setting artid => undef, which translates to artid =
NULL ? Just dont supply that column at all, when you want the database to
supply the default value.
Jess
More information about the DBIx-Class
mailing list