2

我正在 drupal 7.15 中创建一个模块,它依赖于实体 api 。我的模块名称是employee 我已经创建了一个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;
}
4

1 回答 1

1

最初安装模块后,您是否在 .install 文件中添加了 hook_schema()?仅在安装模块时才安装模式。(不要与启用混淆)

尝试完全卸载模块,然后重新安装:

1)禁用模块 2)卸载模块(从管理模块页面上的卸载选项卡) 3)重新安装模块

这应该会在安装时触发 hook_schema。你的钩子实现看起来不错。

如果架构有问题,您应该在安装模块时看到错误。(完全卸载后)如果错误未设置为在屏幕上显示,请检查报告 -> 数据库日志。

另请注意,您无需files[] = employee.module在信息文件中声明。

于 2013-02-25T23:49:45.823 回答