[Dbix-class] Empty inserts with add_to_... and create

apv apv at sedition.com
Thu Jan 12 22:30:16 CET 2006

The only thing I can guess is wrong is that the table is 

A chapter might have a parent chapter and so on. I've never done 
in DBs before but I've had the same concept work in Class::DBI.

Here's the table definition:

CREATE TABLE `chapter` (
   `id` int(8) unsigned NOT NULL auto_increment,
   `doc` int(8) unsigned NOT NULL default '0',
   `chapter` int(8) unsigned default NULL,
   `number` int(4) default NULL,
   `title` tinytext,
   `subtitle` tinytext,
   `created` datetime default NULL,
   `updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
   PRIMARY KEY  (`id`),
   KEY `chapter` (`chapter`),
   KEY `doc` (`doc`),
   CONSTRAINT `chapter_ibfk_1` FOREIGN KEY (`chapter`) REFERENCES 
`chapter` (`id`),
   CONSTRAINT `chapter_ibfk_2` FOREIGN KEY (`doc`) REFERENCES `doc` 

And a sample that's failing (I checked and all the variables are 
defined correctly).

                 title => $chapter,
                 doc => $doc->id,
                 subtitle => $chapter_subtitle,
                 number => $chapter_num,

With the excerpted class def:

__PACKAGE__->add_columns( qw( id doc chapter number title subtitle
                               created updated ));

__PACKAGE__->has_one('doc' => 'Pangyre::Model::doc');
__PACKAGE__->might_have('parent' => 'Pangyre::Model::chapter', 
__PACKAGE__->has_many('chapters' => 'Pangyre::Model::chapter', 
__PACKAGE__->has_many('pages' => 'Pangyre::Model::page', 'chapter');

The related classes are working fine for normal searches and such.

On Thursday, January 12, 2006, at 01:17  PM, Matt S Trout wrote:

> On Thu, Jan 12, 2006 at 12:01:37AM -0800, apv wrote:
>> I'm getting a weird error when trying to create() or add_to_...(). 
>> I've
>> checked my args and such, sorry no code right now, but the underlying
>> stuff seems sound and is working in relational find() or manual 
>> with the identical args. It seems like the args are not even getting
>> passed through to create(). new() works but insert() or create() or
>> add_to...() die with this message:
>> DBD::mysql::st execute failed: Cannot add or update a child row: a
>> foreign key constraint fails [for Statement "INSERT INTO chapter ()
>> VALUES ()"] at
>> /usr/local/lib/perl5/site_perl/5.8.2/DBIx/Class/Storage/DBI.pm line 
>> 187.
>> Does this ring a bell with anyone?
> Is there any chance of you posting some of the code so we can see 
> what's
> going on? Also, what DBIx::Class version are you using?
> -- 
>      Matt S Trout       Offering custom development, consultancy and 
> support
>   Technical Director    contracts for Catalyst, DBIx::Class and BAST. 
> Contact
> Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more 
> information
>  + Help us build a better perl ORM: 
> http://dbix-class.shadowcatsystems.co.uk/ +
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/

More information about the Dbix-class mailing list