innovative kundan
innovative kundan

Reputation: 631

.install file not creating table in drupal

Hi i am very new in drupal. i just create a module that create a form with some inputs. I wrote .install file for the same but it is not creating table. While i am installing this module it is neither showing error nor install table.

function mycontact_schema() {
     $schema['mycontact'] = array(
        'description' => t('This table for mycontact.'),
        'fields' => array(
          'mycontctid' => array(
            'description' => t('The primary identifier for a mycontact.'),
            'type' => 'serial',
            'unsigned' => TRUE,
            'not null' => TRUE),
          'vid' => array(
            'description' => t('The current {mycontact_revisions}.vid version identifier.'),
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'default' => 0),
          'name' => array(
            'description' => t('The {mycontact_name} of this mycontact.'),
            'type' => 'varchar',
            'length' => 32,
            'not null' => TRUE,
            'default' => ''),
          'email' => array(
            'description' => t('The name of this contact, always treated a non-markup plain text.'),
            'type' => 'varchar',
            'length' => 255,
            'not null' => TRUE,
            'default' => ''),
          ),
          'comments' => array(
            'description' => t('The comments of this contact, always treated a non-markup plain text.'),
            'type' => 'text',
            'not null' => TRUE,
            'default' => ''),
        'primary key' => array('mycontctid'),
        );
        return $schema;
    }
It is not showing any error and any warning. 

Upvotes: 3

Views: 693

Answers (1)

Ajit S
Ajit S

Reputation: 1341

There is nothing wrong in the hook_install implementation.
I followed these steps to get it working:

  1. Created a directory called mycontact inside sites/all/modules.
  2. Created a the files mycontact.info, mycontact.module, and mycontact.install.
  3. Inside mycontact.info I added the following lines:

    name = my contact
    core = 7.x
    
  4. And in the mycontact.install file, I copied all the code from the question as it is.
  5. Left the mycontact.module file empty. Note: Drupal needs this empty file.
  6. Enabled the module. And it worked!

What you could do now is, disable the module -> uninstall it -> follow the above steps to install the module; and you should have your database table created for you.

Upvotes: 1

Related Questions