Insert record using Catalyst framework failed.
While using Catalyst to insert a book record, error occurs. After searching info from google, no solution is found. Would you pls offer some advice ?
Here is the controller's code.
sub url_create : Local {
# In addition to self & context, get the title, rating, &
# author_id args from the URL. Note that Catalyst automatically
# puts extra information after the "/<controller_name>/<action_name/"
# into @_
my ($self, $c, $title, $rating, $author_id) = @_;
# Call create() on the book model object. Pass the table
# columns/field values we want to set as hash values
my $book = $c->model('DB::Books')->create({
title => $title,
rating => $rating
});
# Add a record to the join table for this book, mapping to
# appropriate author
$book->add_to_book_authors({author_id => $author_id});
# Note: Above is a shortcut for this:
# $book->create_related('book_authors', {author_id => $author_id});
# Assign the Book object to the stash for display in the view
$c->stash->{book} = $book;
# This is a hack to disable XSUB processing in Data::Dumper
# (it's used in the view). This is a work-around for a bug in
# the interaction of some versions or Perl, Data::Dumper & DBIC.
# You won't need this if you aren't using Data::Dumper (or if
# you are running DBIC 0.06001 or greater), but adding it doesn't
# hurt anything either.
$Data::Dumper::Useperl = 1;
# Set the TT template to use
$c->stash->{template} = 'books/create_done.tt2';
}
However, after accessing URL "http://localhost:3000/books/url_create/TCPIP_Illustrated_Vol-2/5/4", error shows up as :
INSERT INTO books (rating, title) VALUES (?, ?): '5', 'TCPIP_Illustrated_Vol-2'
SELECT COUNT( * ) FROM books me:
SELECT COUNT( * ) FROM books me:
[info] *** Request 1 (0.038/s) [5225] [Thu Aug 14 15:29:27 2008] ***
[debug] "GET" request for "books/url_create/TCPIP_Illustrated_Vol-2/5/4" from "202.38.40.128"
[debug] Path is "books/url_create"
[debug] Arguments are "TCPIP_Illustrated_Vol-2/5/4"
[error] DBI Exception: DBD::Oracle::st execute failed: ORA-01400: cannot insert NULL into ("SDB2"."BOOKS"."ID") (DBD ERROR: OCIStmtExecute) [for Statement "INSERT INTO books (rating, title) VALUES (?, ?)" with ParamValues: :p1='5', :p2='TCPIP_Illustrated_Vol-2'] at /usr/local/lib/perl5/site_perl/5.10.0/DBIx/Class/Schema.pm line 954