2

I am writing a custom module for Drupal 7. For the table creation I have created the .install file, but the table is not getting created automatically, when the module is installed. I have already uninstalled and reinstalled the module many times. All the times I do it, I get the following error:

Base table or view not found: 1146 Table 'drupal.drupalform' doesn't exist

This is the code in the drupalform.install file.

function drupalform_schema() {
    $schema = array();
    $schema['drupalform'] = array(
        'description' => t('A table for holding the drupalform data!'),
        'fields' => array(
            'id' => array(
                'description' => t('Auto increment of the ID'),
                'type' => 'serial',
                'unsigned' => TRUE,
                'not null' => TRUE,
            ),
            'name' => array(
                'description' => t('Person\'s first name.'),
                'type' => 'varchar',
                'length' => 64,
                'not null' => TRUE,
            ),
            'last_name' => array(
                'description' => t('Person\'s last name.'),
                'type' => 'varchar',
                'length' => 64,
                'not null' => TRUE,
            ),
            'email' => array(
                'description' => t('Person\'s email'),
                'type' => 'varchar',
                'length' => 64,
                'not null' => TRUE
            ),
        ),
        'primary key' => array('id'),
    );
    return $schema;
}

function drupalform_install() {
    drupal_install_schema('drupalform');
}

function drupalform_uninstall() {
    drupal_uninstall_schema('drupalform');
}
5
  • Have you definitely uninstalled it and re-installed it, or just disabled and re-enabled? Assuming your module is named drupalform, that code is fine
    – Clive
    Commented Jul 25, 2016 at 12:09
  • The module was uninstalled and reinstalled.
    – fanatic
    Commented Jul 25, 2016 at 12:19
  • Verify whether any error is getting logged (recent log messages) while you are installing your module.
    – Deb
    Commented Jul 25, 2016 at 12:24
  • It is showing two messages: 1). 1 orphaned actions (registration_views_set_state_action) exist in the actions table. Remove orphaned actions. 2). drupalform module enabled.
    – fanatic
    Commented Jul 25, 2016 at 12:40
  • declare primary key like below, 'code' 'primary key' = array('id'), and remove drupal_install_schema('drupalform'); from your hook_install
    – Deb
    Commented Jul 25, 2016 at 13:15

1 Answer 1

3

The following line is not correct.

'primary_key' => array('id'),

Replace 'primary_key' with 'primary key'.

In Drupal 7 you do not need to call drupal_install_schema() nor drupal_uninstall_schema() for the database tables your module uses.

You can just declare the functions.

function drupalform_install() {}

function drupalform_uninstall() {}

Just update the code, uninstall the module, and re-install it.

5
  • It was 'primary key' before not 'primary_key'. By the way. it is also not working. I already removed the: unction drupalform_install() { drupal_install_schema('drupalform'); } function drupalform_uninstall() { drupal_uninstall_schema('drupalform'); }
    – fanatic
    Commented Jul 25, 2016 at 13:44
  • What is the error message you get now. Have you uninstall the module and reinstall it or only disable and enable it.
    – DRUPWAY
    Commented Jul 25, 2016 at 13:47
  • I am installing the module not enable or disable. Recent log is showing two messages: 1). 1 orphaned actions (registration_views_set_state_action) exist in the actions table. Remove orphaned actions. 2). drupalform module enabled.
    – fanatic
    Commented Jul 25, 2016 at 13:53
  • Could it be phpmyadmin issue?
    – fanatic
    Commented Jul 25, 2016 at 13:54
  • There is no issue code. Some other issue. I am able to create table using your code.
    – DRUPWAY
    Commented Jul 25, 2016 at 13:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.