您在這裡

用API新增Table

caxton's 的頭像
caxton 在 2009-02-09 (週一) 16:35 發表

大家好:

我最近剛接觸drupal
並試著看著書的範例
寫個簡單的自訂模組
遇到一個和資料庫有關的問題
我利用drupal_install_schema這個API要新增一個table
可是模組啟動後 並沒有成功新增
但是也沒有任何錯誤訊息
網路上找了相關的資料
目前找不到有什麼明顯的錯誤
所以有點卡住了
下面是程式片段
還請各位高手幫忙
謝謝


function annotate_install() {
// Use schema API to create database table.
drupal_install_schema('annotate');
}

function annotate_schema() {
$schema['annotations'] = array(
'description' => t('Stores node annotations that users write.'),
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The {node}.nid to which the annotation applies.'),
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The {user}.uid of the user who created the annotation.'),
),
'note' => array(
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'description' => t('The text of the annotation.'),
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => t('A Unix timestamp indicating when the annotation was created.'),
),
), // end of fields
'primary key' => array(
'nid', 'uid',
),
);
return $schema;
}