15

I'm trying to create a module for Drupal 7 and I need to create 3 tables and populate it. But first i need to create it.

In the file mymodule.install I have got

function mymodule_install() {

}

function mymodule_uninstall() {

}


function myodule_schema() {
  $schema['mymodule_table'] = array(
    'description' => t('First table'),
    'fields' => array(
      'id' => array(
        'description' => t('My unique identifier'),
        'type' => 'int',
        'unsigned' => true,
        'not null' => true,
      ),
      'list' => array(
        'description' => t('list'),
        'type' => 'varchar',
        'not null' => true,
      ),
    ),
    'primary key' => array('id'),
  );
  return $schema;     
}

What am I doing wrong? Every time I test the module, I disable it -> uninstall -> Performance clear cache -> enable it.

  • 3
    If you have drush and devel installed you could use drush devel-reinstall mymodule to quickly reinstall your module – FLY May 17 '13 at 9:23
11

You're missing the length property for the varchar column ('list'). length is required so the CREATE TABLE query will fail.

From the Schema API docs:

All parameters apart from 'type' are optional except that type 'numeric' columns must specify 'precision' and 'scale', and 'varchar' columns must specify 'length'.

4

myodule_schema has a typo. An m is missing after the y.

  • Thanks BetaRide, it was a transcription mistake. I give you one vote up because you have read my post and actually I really found a spelling mistake on the name of the function eh eh – Tyler Durden Jun 27 '12 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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