DBIx::Class 新建和创建时出错

DBIx::Class Error on New and Create

我在 Dancer2 项目中使用 DBIx::Class 与 MySQL 数据库对话。在那个项目中,我有一个 ClassInfo 结果集,我可以 select 从中搜索、删除和更新,没有问题。

但是,每当我尝试添加新行时,通过:

my $new_class = $SCHEMA->resultset( 'ClassInfo' )->new({});

my $new_class = $SCHEMA->resultset( 'ClassInfo' )->create({});

(为简洁起见省略了数据),我收到以下错误:

DBIx::Class::Row::has_column_loaded(): Can't call has_column data as class method at /home/jlamey/src/dancer_projects/QP/bin/../lib/QP.pm line 2109

2104      {
2105        flash error => sprintf( 'Class <strong>%s</strong> already exists.' );
2106        redirect '/admin/manage_classes/classes';
2107      }
2108    
2109      my $new_class = $SCHEMA->resultset( 'ClassInfo' )->new(
2110        {
2111          title                => body_parameters->get( 'title' ),
2112          description          => body_parameters->get( 'description' ),
2113          class_group_id       => body_parameters->get( 'class_group_id' ),
2114          class_subgroup_id    => ( body_parameters->get( 'class_subgroup_id' )    ? body_parameters->get( 'class_subgroup_id' )    : undef ),

我什至尝试用 数据提交 'new' 和 'create' 命令,只是为了确保不是导致错误的数据, 仍然报错。

它试图写入的 table 看起来像这样:

+----------------------+---------------------+------+-----+---------+----------------+
| Field                | Type                | Null | Key | Default | Extra          |
+----------------------+---------------------+------+-----+---------+----------------+
| id                   | int(8) unsigned     | NO   | PRI | NULL    | auto_increment |
| class_group_id       | int(8) unsigned     | NO   | MUL | 1       |                |
| class_subgroup_id    | int(8) unsigned     | YES  | MUL | NULL    |                |
| teacher_id           | int(8) unsigned     | YES  | MUL | NULL    |                |
| secondary_teacher_id | int(8) unsigned     | YES  | MUL | NULL    |                |
| tertiary_teacher_id  | int(8) unsigned     | YES  | MUL | NULL    |                |
| title                | varchar(255)        | NO   | MUL |         |                |
| description          | text                | NO   |     | NULL    |                |
| num_sessions         | varchar(255)        | YES  |     | NULL    |                |
| fee                  | varchar(100)        | YES  |     | NULL    |                |
| skill_level          | varchar(255)        | YES  |     | NULL    |                |
| is_also_embroidery   | tinyint(1) unsigned | YES  | MUL | 0       |                |
| is_also_club         | tinyint(1) unsigned | YES  | MUL | 0       |                |
| show_club            | tinyint(1) unsigned | YES  |     | 0       |                |
| image_filename       | varchar(255)        | YES  |     | NULL    |                |
| supply_list_filename | varchar(255)        | YES  |     | NULL    |                |
| no_supply_list       | tinyint(1) unsigned | YES  |     | 0       |                |
| always_show          | tinyint(1) unsigned | YES  |     | 0       |                |
| anchor               | varchar(5)          | YES  |     | NULL    |                |
| new                  | tinyint(1) unsigned | YES  |     | 0       |                |
+----------------------+---------------------+------+-----+---------+----------------+

结果集如下所示:

package QP::Schema::Result::ClassInfo;

use base qw/DBIx::Class::Core/;

__PACKAGE__->table( 'classes' );

__PACKAGE__->add_columns(
                          id =>
                          {
                            data_type         => 'integer',
                            size              => 8,
                            is_nullable       => 0,
                            is_auto_increment => 1,
                          },
.
.
.
                          new =>
                          {
                            data_type         => 'boolean',
                            is_nullable       => 0,
                            default_value     => 0,
                          },
                        );

__PACKAGE__->set_primary_key( 'id' );

__PACKAGE__->belongs_to( teacher     => 'QP::Schema::Result::Teacher',       'teacher_id' );
__PACKAGE__->belongs_to( teacher2    => 'QP::Schema::Result::Teacher',       'secondary_teacher_id' );
__PACKAGE__->belongs_to( teacher3    => 'QP::Schema::Result::Teacher',       'tertiary_teacher_id' );
__PACKAGE__->belongs_to( class_group => 'QP::Schema::Result::ClassGroup',    'class_group_id' );
__PACKAGE__->belongs_to( subgroup    => 'QP::Schema::Result::ClassSubgroup', 'class_subgroup_id' );

__PACKAGE__->has_many( dates => 'QP::Schema::Result::ClassDate', 'class_id' );

1;

我很茫然;此项目中没有其他结果集有此问题,它们都是以相同的方式构建的。

在此先感谢您的帮助。 -- 杰森

您有一个名为 new 的列,它创建了一个名为 new 的访问器方法,从而覆盖了 类 的构造函数方法。 这类似于 DBIx::Class::Manual::Troubleshooting/syntax error at or near "" ....