我在drupal 7.15中创建了一个依赖于实体api的模块。 我的模块名称是员工 我创建了一个employee.info文件以及employee.install文件。 但是在数据库中,我无法在employee.install文件中看到我自己创建的数据库模式。 这是我的.info文件和.install文件 编辑:
name = Employee Management
description = A module that describes about the employee management
core = 7.x
package = Employee management module
files[] = employee.module
编辑:
<?php
/**
* @file
* Install for a employee entity - need to create the base table for our entity.
* This table can have as many colums as you need to keep track of entity-specific
* data that will not be added via attached fields.
* The minimum information for the entity to work is an id and an entity name.
*/
/**
* Implements hook_schema()
*/
function employee_schema() {
$schema = array();
$schema['employee'] = array(
'description' => 'The base table for employee entity.',
'fields' => array(
'employee_id' => array(
'description' => 'Primary Key: Identifier for a employee entity.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'first_name' => array(
'description' => 'The First name of employee entity.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'last_name' => array(
'description' => 'The Last name of employee entity.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'employee_add' => array(
'description' => 'The address of employee entity.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'employee_doj' => array(
'description' => 'The address of employee entity.',
'type' => 'date',
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('employee_id'),
);
return $schema;
}
答案 0 :(得分:1)
在最初安装模块后,您是否在.install文件中添加了hook_schema()?只有在安装模块时才会安装架构。 (不要与启用混淆)
尝试完全卸载模块,然后重新安装:
1)禁用模块 2)卸载模块(从管理模块页面上的卸载选项卡) 3)重新安装模块
这应该在安装时触发hook_schema。你的钩子实现看起来很好。
如果架构出现问题,则在安装模块时应该会看到错误。 (完全卸载后)如果未将错误设置为在屏幕上显示,请检查报告 - &gt; db log。
另请注意,您无需在信息文件中声明files[] = employee.module
。