我在用Drupal制作一个考勤系统。现在创建了一个请假的module:absence,然后想用代码实现创建对应的数据库absent。我是照着17drupal上第二章写的,代码如下:
//$Id$
/**
* Implementation of hook_install().
*/
function absence_install(){
//Use schema API to create database table.
drupal_install_schema('absence');
}
/**
*Implementation of hook_uninstall().
*/
function absence_uninstall(){
//Use schema API to delete database table.
drupal_uninstall_schema('absence');
//delete our module's variable from the variables table.
variable_del('absence_node_types');
}
/**
* Implementation of hook_schema().
*/
function absence_schema() {
$schema['absent'] = array(
'description' => t('Stores node absent that users write.'),
'fields' => array(
'name' => array(
'type' => 'varchar',
'not null' => TRUE,
),
'Date' => array(
'type' => 'date',
'not null' => TRUE,
),
'Absence' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'Code' => array(
'type' => 'varchar',
'not null' => TRUE,
),
),
'primary key' => array(
'name', 'Date'
),
);
return $schema;
}
可是,数据库中没有建立起相应的absent表,并且在卸载和重装了该模块后,提示错误如下:
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, `Date` NOT NULL, `Absence` INT NOT NULL DEFAULT 0, `Code` VARCHAR ' at line 2 query: CREATE TABLE absent ( `name` VARCHAR NOT NULL, `Date` NOT NULL, `Absence` INT NOT NULL DEFAULT 0, `Code` VARCHAR NOT NULL, PRIMARY KEY (name, Date) ) /*!40100 DEFAULT CHARACTER SET utf8 */ in D:\wamp\www\timesheet1\includes\database.inc on line 551.
大家帮忙看看啊,谢谢啦
补充一下,我用的是Drupal6.20的


新浪微博
腾讯微博