Hi All,

I'm a beginner of Drupal 6, and have been following the steps outlined in John K VanDyk's Drupal Pro Development 2nd Edn to get a hold of how to make Drupal modules.

So I just created the install file and now when i disabled and re-enabled the module, the new table is not being created. I've been trying to figure this out but am failing so I'm turning to the masses. Also when I try to uninstall (even though the install didnt happen, the variable delete function comes up as undefined)

<?php
function annotate_install() {
// Use schema API to create database table.
echo (drupal_install_schema('annotate'));
}

function annotate_uninstall() {
// Use schema API to delete database table.
drupal_uninstall_schema('annotate');
// Delete our module's variable from the variables table.
variable_delete('annotate_node_types');
}

function annotate_schema() {
$schema['annotations'] = array(
'description' => t('Stores node annotations that users write.'),
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The {node}.nid to which the annotation applies.'),
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('The {user}.uid of the user who created the annotation.')
),
'note' => array(
'description' => t('The text of the annotation.'),
'type' => 'text',
'not null' => TRUE,
'size' => 'big'
),
'created' => array(
'description' => t('A Unix timestamp indicating when the annotation
was created.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0
),
),
'primary key' => array(
'nid', 'uid'
),
);
return $schema;
}

Comments

mafaz’s picture

The db I'm using is MySQL and the webserver is APACHE running on my local machine

mafaz’s picture

Seems that installing the Schema module does the trick..so for those out there with a similar issue..voila! :)

jaypan’s picture

The problem is that tables aren't added or removed from the database when you disable and enable a module. The tables are only installed on first install, and removed if you go to the uninstall tab after disabling the module.

The reason for this is that you are supposed to disable all modules when upgrading Drupal. But of course you don't want to lose all data when you do this, so they leave all the tables in place for disabling and enabling.

Contact me to contract me for D7 -> D10/11 migrations.

wesayso’s picture

when i disabled and re-enabled the module, the new table is not being created

As Jay said, to uninstall a module you must first disable it, then click the "Uninstall" tab at the top of the module administration page and tell Drupal to uninstall it.

For a quicker way to uninstall & reinstall a module, install the Devel module. It provides a number of things that are useful when you're developing a module, including a "Reinstall modules" menu item which makes it easy to uninstall & reinstall a module.

the variable delete function comes up as undefined

You want to call variable_del, not variable_delete.

bartgo’s picture

Have a glance at the errata on http://www.drupalbook.com/errata2