gpt4 book ai didi

drupal-7 - .install 文件不在 drupal 中创建表

转载 作者:行者123 更新时间:2023-12-02 03:27:29 24 4
gpt4 key购买 nike

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

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 中创建了一个名为 mycontact 的目录。
  2. 创建了文件 mycontact.infomycontact.modulemycontact.install
  3. mycontact.info 中,我添加了以下几行:

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

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

关于drupal-7 - .install 文件不在 drupal 中创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29668395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com