For the last few hours I have been trying to create database table in my custom module with no luck!! The documentation says that you only need to implement hook_schema in Drupal 7 and the Drupal takes care of creating the table during module installation. I just cant figure out why the table is not created. I tried installing the module through Drupal admin as well as pasting in the module folder but it still doesnt work.
Here is my function inside .install file:
/**
* @return array an array containing table's field definitions
* to be created by drupal schema api
*/
function inquiry_form_schema() {
$schema['inquiry_form'] = array(
'description' => 'Table to record inquiries submitted by staff',
'fields' => array(
'ID' => array(
'description' => 'The primary key of the table',
'type' => 'serial',
'size' => 'big',
'not null' => TRUE,
),
'sender' => array(
'description' => 'The person who submits the inquiry',
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'subject' => array(
'description' => 'Title of the inquiry being submitted',
'type' => 'char',
'length' => '100',
'not null' => TRUE,
),
'department' => array(
'description' => 'The department that the inquiry is being referenced to',
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'description' => array(
'description' => 'Detailed explanation of the issue the sender is experiencing',
'type' => 'text',
'not null' => TRUE,
),
// 'date' => array(
// 'description' => 'Date of the inquiry being submitted',
// 'mysql_type' => 'datetime',
// 'not null' => TRUE,
// ),
),
'primary key' => array('ID'),
);
return $schema;
}
I'm assuming your files are: - inquiry_form.info - inquiry_form.module - inquiry_form.install
Is this the case?
Make sure the length is not quoted. Should be 100 and not '100'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.