1

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;
}

1 Answer 1

1

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'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.