Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal7 .install script not working

I am trying to convert my module from drupal6 to drupal 7 this is my code. The database table is not created.

function example_install() {
  drupal_install_schema('example');
}
/**
 * Implements hook_schema().
 */
function example_schema() {
  $schema['example'] = array(
    'description' => 'example settings',
    'fields' => array(
      'name' => array(
        'description' => 'name',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
      ),

      'age' => array(
        'description' => 'age',
        'type' => 'int',
    'size' => 'tiny',
        'not null' => TRUE,
      ),
)    ,
);
  return $schema;
}

Can any one explain whats wrong.

like image 613
Ramesh Avatar asked Mar 12 '26 23:03

Ramesh


1 Answers

You don't want to run drupal_install_schema() yourself in Drupal 7, hook_schema() is called automatically if it exists in the .install file. That will probably cause a few problems but you'd still expect the table to be created at least once.

Once you've removed hook_install() try uninstalling (not just disabling) your module, then re-enabling it. I recommend the Devel module to do this as it provides a page (devel/reinstall) where you can easily force a reinstall of a module.

If you don't want to do that though, go to the modules page, disable the module, then click the 'Uninstall' tab at the top to uninstall it fully. Then go back to the modules page and re-enable it.

Doing this should force Drupal to re-run your hook_schema() script and the table should be created.

like image 169
Clive Avatar answered Mar 14 '26 20:03

Clive