我是drupal新手,在自定义模块上工作,这是我的.install文件代码,但当我安装模块时,它不会在数据库中创建表。谁能告诉我我错在哪里?
<?php
function make_application_schema()
{
$schema['make_master'] = array(
'description' => 'Make master table',
'fields' => array(
'make_id' => array(
'description' => 'make id primary key auto increment',
'type' => 'serial',
'not null' => TRUE,
),
'make_name' => array(
'description' => 'Make name',
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'make_status' => array(
'description' => 'check make status',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
),
'primary key' => array('make_id'),
);
return $schema;
}
function make_application_install()
{
}
function make_application_uninstall()
{
}
您的模块名称是什么?当您安装并使用hook_schema时,您应该像这样命名您的函数:
my_module.module
在my_module.installfunction my_module_schema () ....
…之后,这应该是工作:)
为了安装数据库'make_master',您必须使用模块名称:
调用drupal_install_schemadrupal_install_schema('make_application');
根据你的问题,我想你忘记调用drupal_install_schema
函数了。这里是更新的make_application_install
和make_application_uninstall
的make_application.install.
function make_application_install() {
// Use schema API to create database table.
drupal_install_schema('make_master');
}
function make_application_uninstall() {
// Remove tables.
drupal_uninstall_schema('make_master');
}
注意
表不会在模块启用时安装,它们只会在第一次安装时安装。首先,禁用模块,然后单击"uninstall"选项卡,选择模块,并卸载它(注意:如果你的模块没有hook_uninstall()函数,它不会出现在这里-确保你已经添加了这个函数)。然后,单击列表选项卡,重新启用模块。这是第一次安装,表将安装。
或者使用devel模块,启用开发块,然后在块中使用'重新安装模块'链接。
您可以参考此链接获取更多信息:https://www.drupal.org/node/811594