<br><br><div class="gmail_quote">On Tue, Nov 10, 2009 at 5:53 AM, Jordi Amorós <span dir="ltr"><<a href="mailto:jamoros@etsetb.upc.edu">jamoros@etsetb.upc.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
I'm developing a little web application (a remote lab that works with<br>
Catalyst+LabView). Until now I was using SQLite, but due to new<br>
requirements I've had to migrate the database.<br>
<br>
I've created a new model:<br>
perl script/<a href="http://ilabrs_create.pl" target="_blank">ilabrs_create.pl</a> model DB DBIC::Schema ilabrs::Schema<br>
create=static components=TimeStamp,EncodedColumn dbi:mysql:ilabrs<br>
<br>
and then, after restarting the server all seemed to work. Actually,<br>
list, edit and erase from the database is working fine. But when I want<br>
to add data, it doesn't work.<br>
<br>
The problem appears when an id it's not provided. If I'm not wrong,<br>
"my $exp = $c->model('DB::Activitats')-> find_or_new({id=> $id});"<br>
should solve that. But: "$c->log->debug("Experiment ID:".$exp->id);",<br>
prints nothing.<br>
<br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'm absolutely clueless. I've tried to split de edit function in two:<br>
-one to actually edit (my $exp = $c->model('DB::Activitats')-><br>
find({id=> $id});) which still works properly.<br>
<br>
-and a second one to add (my $exp = $c->model('DB::Activitats')-><br>
new({});) which doesn't because $exp->id is empty and<br>
$exp->update_or_insert;<br>
cause an exception:<br>
<br>
DBI Exception: DBD::mysql::st execute failed: Column 'id' cannot be<br>
null...<br>
<br>
Any suggestion, idea, clue... will be welcome.<br>
<br>
Thanks,<br>
<br>
</blockquote><div><br>This is a DBIC question, as such the answer is clearly found in the DBIC manual:<br>
<a href="http://search.cpan.org/~ribasushi/DBIx-Class-0.08112/lib/DBIx/Class/ResultSet.pm#find_or_new">http://search.cpan.org/~ribasushi/DBIx-Class-0.08112/lib/DBIx/Class/ResultSet.pm#find_or_new</a><br>
<br>To summarize, ->new or ->find_or_new will not create a record in the database (and as such, no id is available). If you want to create a record, triggering the auto_increment, then you must use create or a subsequent ->insert after a ->new call.<br>
</div></div><br>Also of note, DBIx::Class has its own mailing list that you should consider subscribing to.<br><br>Thanks,<br>-Jay<br>