I have a simple script:
use lib 'lib'; use Party::M::CDBI::Declaration; my $a = Party::M::CDBI::Declaration->create({freetext => 'aaasdds'});
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:
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
Interestingly when I run in psql I omit the 'id' in the values the statement works:
INSERT INTO declaration (freetext) VALUES ('aaasdds');
Here is the the rest of the relevant code:
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 );

In reply to Class::DBI and 'serial' columns in PostgreSQL by zby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.