<br><br><div class="gmail_quote">On Tue, Nov 10, 2009 at 5:53 AM, Jordi Amorós <span dir="ltr">&lt;<a href="mailto:jamoros@etsetb.upc.edu">jamoros@etsetb.upc.edu</a>&gt;</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&#39;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&#39;ve had to migrate the database.<br>
<br>
I&#39;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&#39;t work.<br>
<br>
The problem appears when an id it&#39;s not provided. If I&#39;m not wrong,<br>
&quot;my $exp = $c-&gt;model(&#39;DB::Activitats&#39;)-&gt; find_or_new({id=&gt; $id});&quot;<br>
should solve that. But: &quot;$c-&gt;log-&gt;debug(&quot;Experiment ID:&quot;.$exp-&gt;id);&quot;,<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&#39;m absolutely clueless. I&#39;ve tried to split de edit function in two:<br>
-one to actually edit (my $exp = $c-&gt;model(&#39;DB::Activitats&#39;)-&gt;<br>
find({id=&gt; $id});) which still works properly.<br>
<br>
-and a second one to add (my $exp = $c-&gt;model(&#39;DB::Activitats&#39;)-&gt;<br>
new({});) which doesn&#39;t because $exp-&gt;id is empty and<br>
$exp-&gt;update_or_insert;<br>
cause an exception:<br>
<br>
DBI Exception: DBD::mysql::st execute failed: Column &#39;id&#39; 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, -&gt;new or -&gt;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 -&gt;insert after a -&gt;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>