1

I am new to Drupal, and I am trying to write a module with an .install file which will create a database table. The table isn't being created (as seen from the error codes when I try to access it. It also doesn't show up in the Schema module listing) and I don't know what I did wrong. Can someone see if they can find the error?

This is the code:

function email_form_schema() {  
  $schema['subscription_info'] = array(
    'description' => t('The base table for nodes.'),
    'fields' => array(
      'first' => array(
        'description' => t('The first name'),
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
      ),
      'last' => array(
        'description' => t('The last name'),
        'type' => 'varchar',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => '',
      ),
      'email' => array(
        'description' => t('The email address'),
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => ''
      ),
      'phone' => array(
        'description' => t('The phone number.'),
        'type' => 'varchar',
        'length' => 10,
        'not null' => TRUE,
        'default' => '',
      )
     ),
    'primary key' => array('email'),
  );

  return $schema;
}   

function email_form_install() {
  // Create my tables.
  drupal_install_schema('email_form');
}

function email_form_uninstall() {
  // Drop my tables.
  drupal_uninstall_schema('email_form');
}   

Here's the error when I try to access it:

user warning: Table 'drupal620x120318224310.subscription_info' doesn't exist query: INSERT INTO subscription_info (first, last, email, phone) VALUES ('','','','') in C:\EasyPHP-5.3.8.1\modules\drupal620x120318224310\sites\all\modules\email_form\email_form.module on line 123.

I was missing the return $schema; line (which I modified above), but it still doesn't work. In the schema module it lists the "subscription_info" table as missing. What does this mean?

1 Answer 1

2

If I had a penny for every time I've done this...

You've forgotten to return $schema from your email_form_schema() function.

You'll need to reinstall the module (not just disable then re-enable) for the changes to take effect.

There's also a problem with the "last" column. It's a "varchar" and you're using the "unsigned" property which isn't compatible with that type.

You also need to provide the "length" property for all of the "varchar" type columns, including "first" and "last".

12
  • Oops. You're right. But now (in the Schema Module) I now have the error: Tables in the [email_form] schema aren't present in the database, and I still can't access the table. What does this mean? Commented Mar 28, 2012 at 19:29
  • 1
    I remember this happening in Drupal 6, how are you reinstalling the module? If you're not already I'd install the Devel module then visit mysite.com/devel/reinstall. If memory serves selecting to reinstall the module at that path a couple of times will stop the errors and install the table correctly
    – Clive
    Commented Mar 28, 2012 at 19:46
  • I have been uninstalling it manually on the module page. I tried it your way and got the following: Commented Mar 28, 2012 at 19:56
  • 1
    @Clive I would add what you reported in your last comment as part of the answer, in that way, who reads your answer doesn't need to read 7 comments to find some relevant, and important information to know.
    – avpaderno
    Commented Mar 28, 2012 at 21:27
  • 1
    @Clive Whoops… Never mind. I mis-read it.
    – avpaderno
    Commented Mar 29, 2012 at 1:44

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.