Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.install file not creating table in drupal

Tags:

drupal-7

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. 
like image 571
innovative kundan Avatar asked Aug 16 '26 06:08

innovative kundan


1 Answers

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.

like image 95
Ajit S Avatar answered Aug 20 '26 06:08

Ajit S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!