0

我在使用架构模块和我创建的表时遇到问题。我使用模式来创建模式,然后当我尝试安装模块 logo_management 时,出现此错误:

Invalid default    value for 'logoid': 

CREATE TABLE {logo} ( `logoid` INT unsigned NULL auto_increment DEFAULT     
0 COMMENT 'Unique Logo ID', `date_created` NULL DEFAULT 0 COMMENT 
'The date the logo was    added.', `category` VARCHAR(50) NULL DEFAULT 
'OTHER' COMMENT 'The category the logo should be in.', `no_of_lines` 
INT NULL DEFAULT 1 COMMENT 'Number of lines(1 or 2)', 
`line_1` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Line 1 for Logo', 
`line_2` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Line 2 for Logo', 
`image_path` VARCHAR(100) NULL DEFAULT NULL COMMENT 
'Path and filename for image', `activate` 
 INT NULL DEFAULT 0 COMMENT 'Boolean if the logo should be active or not.', 
PRIMARY KEY (`logoid`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 

这是我拥有的 .install 架构。我假设'logoid'的无效默认值有问题,但是我尝试输入默认值,它仍然给我同样的错误。

function logo_management_schema() {
    $schema['logo'] = array(
      'description' => 'Logo Management Module',
       'fields' => array(
        'logoid' => array(
        'description' => 'Unique Logo ID',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
        'date_created' => array(
        'description' => 'The date the logo was added.',
        'type' => 'date',
        'not null' => TRUE,
    ),
    'category' => array(
      'description' => 'The category the logo should be in.',
      'type' => 'varchar',
      'length' => '50',
      'not null' => TRUE,
      'default' => 'OTHER',
    ), 
    'no_of_lines' => array(
      'description' => 'Number of lines(1 or 2)',
      'type' => 'int',
      'not null' => TRUE,
      'default' => 1,
    ),
    'line_1' => array(
      'description' => 'Line 1 for Logo',
      'type' => 'varchar',
      'length' => '100',
      'not null' => TRUE,
    ),
    'line_2' => array(
      'description' => 'Line 2 for Logo',
      'type' => 'varchar',
      'length' => '100',
      'not null' => FALSE,
    ),
    'image_path' => array(
      'description' => 'Path and filename for image',
      'type' => 'varchar',
      'length' => '100',
      'not null' => TRUE,
    ),
    'activate' => array(
      'description' => 'Boolean if the logo should be active or not.',
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    ),
  ),
  'primary key' => array('logoid'),
);

return $schema;
}
4

1 回答 1

0

技巧和决心解决了这个问题!将类型更改为 int。

$schema['logo'] = array(
      'description' => 'Logo Management Module',
      'fields' => array(
        'logoid' => array(
          'description' => 'Unique Logo ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        )

然后我遇到了日期问题并将其更改为:

    'date_created' => array(
      'description' => 'The date the logo was added.',
      'type' => 'datetime',
      'mysql_type' => 'DATETIME',
      'not null' => TRUE,
    ),

现在我的模块安装了!

于 2013-06-07T22:42:52.587 回答