使用Drupal hook_schema()创建数据库表

时间:2016-10-02 22:42:27

标签: php drupal-7

最近几个小时我一直试图在我的自定义模块中创建数据库表而没有运气!文档说你只需要在Drupal 7中实现hook_schema,Drupal负责在模块安装期间创建表。我只是想弄清楚为什么没有创建表。我尝试通过Drupal管理员安装模块以及粘贴在模块文件夹中,但它仍然无法正常工作。

这是我的函数.install文件:

/**
 * @return array an array containing table's field definitions
 * to be created by drupal schema api
 */
function inquiry_form_schema() {

  $schema['inquiry_form'] = array(
    'description' => 'Table to record inquiries submitted by staff',
    'fields' => array(
      'ID' => array(
        'description' => 'The primary key of the table',
        'type' => 'serial',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'sender' => array(
        'description' => 'The person who submits the inquiry',
        'type' => 'varchar',
        'length' => '100',
        'not null' => TRUE,
      ),
      'subject' => array(
        'description' => 'Title of the inquiry being submitted',
        'type' => 'char',
        'length' => '100',
        'not null' => TRUE,
      ),
      'department' => array(
        'description' => 'The department that the inquiry is being referenced to',
        'type' => 'varchar',
        'length' => '100',
        'not null' => TRUE,
      ),
      'description' => array(
        'description' => 'Detailed explanation of the issue the sender is experiencing',
        'type' => 'text',
        'not null' => TRUE,
      ),
//      'date' => array(
//        'description' => 'Date of the inquiry being submitted',
//        'mysql_type' => 'datetime',
//        'not null' => TRUE,
//      ),
    ),
    'primary key' => array('ID'),
  );

  return $schema;
}

1 个答案:

答案 0 :(得分:0)

我假设您的文件是: - inquiry_form.info - inquiry_form.module - inquiry_form.install

是这样的吗?

确保未引用长度。 应该是100而不是' 100'