简体   繁体   English

DBIx::Class 尝试使用 ->create() 时出现未定义值异常

[英]DBIx::Class undefined value exception when trying to use ->create()

I'm trying to create a new row using DBIx::Class from within Catalyst, with the following code:我正在尝试使用 Catalyst 中的 DBIx::Class 创建一个新行,代码如下:

$c->model('Session')->resultset('UserPreference')->create(
                {
                 appname => 'rss_reader',
                 username => $username,
                 data => $data,
                },
               );

But, I hit this error every time:但是,我每次都遇到这个错误:

Caught exception in App::Controller::rss->dbo "Can't call method "resolve" on an undefined value at /etg/source/Linux/pkg/perl-5.8.8/lib/site_perl/5.8.8/DBIx/Class/Row.pm line 1309."

I see a few mailing lists talking about this error being thrown as an incorrect blanket error when the query fails for whatever reason (perms, constraints,etc.), but it looks just fine AND even running with DBIC_TRACE=1, I don't even see the generated query in my console.我看到一些邮件列表谈论当查询由于任何原因(perms、约束等)失败时,这个错误被抛出为不正确的一揽子错误,但它看起来很好,甚至在 DBIC_TRACE=1 的情况下运行,我不甚至在我的控制台中查看生成的查询。

I should mention I don't think there's something bad with the permissions,etc.我应该提一下,我不认为权限等有什么不好的地方。 since using the database handle manually works:因为手动使用数据库句柄:

my $stm=$c->model("Session")->storage->dbh->prepare("insert into user_preferences (username,appname,data) values ('mphillip','rss_reader','cookies')"); $stm->execute(); 

Have you tried update_or_create instead of create ?您是否尝试过update_or_create而不是create If a row exists create will fail.如果存在一行,则create将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM