3

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. 
1
  • how do you uninstall it? Just disable it? Try 'Un installing' it as well. Commented Apr 16, 2015 at 11:13

1 Answer 1

1

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.

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

4 Comments

Why i need to leave empty .module file. what i did created mycontact.info file put information in this. created mycontact.module file enable it. and check my form it is working fine. After that i create .install file and disable module and enable again, form is looking fine but table is not created in database.
@innovativeKundan not necessary to keep the file empty. I was just trying to emphasize that drupal needs this file.
The hook_schema only gets fired when the module is installed and not every time it is enabled. To create the table, you should uninstall the module after disabling it. And the enable it again to trigger the hook.
Yeh.. thanx @Ajit s actually i did the same and it works. I uninstall module and install it again. Thanks Ajit s. Like it

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.