.install 文件未在 drupal 中创建 table

.install file not creating table in drupal

嗨,我是 drupal 的新手。我只是创建一个模块来创建一个带有一些输入的表单。我为此编写了 .install 文件,但它没有创建 table。当我安装这个模块时,它既没有显示错误也没有安装 table。

function mycontact_schema() {
     $schema['mycontact'] = array(
        'description' => t('This table for mycontact.'),
        'fields' => array(
          'mycontctid' => array(
            'description' => t('The primary identifier for a mycontact.'),
            'type' => 'serial',
            'unsigned' => TRUE,
            'not null' => TRUE),
          'vid' => array(
            'description' => t('The current {mycontact_revisions}.vid version identifier.'),
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'default' => 0),
          'name' => array(
            'description' => t('The {mycontact_name} of this mycontact.'),
            'type' => 'varchar',
            'length' => 32,
            'not null' => TRUE,
            'default' => ''),
          'email' => array(
            'description' => t('The name of this contact, always treated a non-markup plain text.'),
            'type' => 'varchar',
            'length' => 255,
            'not null' => TRUE,
            'default' => ''),
          ),
          'comments' => array(
            'description' => t('The comments of this contact, always treated a non-markup plain text.'),
            'type' => 'text',
            'not null' => TRUE,
            'default' => ''),
        'primary key' => array('mycontctid'),
        );
        return $schema;
    }
It is not showing any error and any warning. 

hook_install 实现没有任何问题。
我按照以下步骤让它工作:

  1. sites/all/modules.
  2. 中创建了一个名为 mycontact 的目录
  3. 创建了文件 mycontact.infomycontact.modulemycontact.install
  4. mycontact.info里面我添加了以下几行:

    name = my contact
    core = 7.x
    
  5. 并且在 mycontact.install 文件中,我原样复制了问题中的所有代码。
  6. mycontact.module 文件留空。 注意:Drupal 需要这个空文件。
  7. 启用模块。它奏效了!

您现在可以做的是,禁用该模块->卸载它->按照上述步骤安装该模块;并且您应该已经为您创建了数据库 table。