Hi,

I'm making my first Drupal module with help of the Pro Drupal Development book :).

The book is great and everything is well explained, I got to the chapter where I must create a database table when activating my module.

Now the code is very clear for me since I'm a PHP developer since 2 years now, but for some reason my table isn't created and I don't get any errors, error log shows nothing either.

Here's my code in my .install file.

<?php

// $Id$

/**
* Implementation of hook_install().
*/

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

/**
* Implementation of hook_uninstall().
*/

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');
}

/**
* Implementation of hook_schema().
*/

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 {node}.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 annotation was created.'),
								  									  'type' => 'int',
								  									  'not null' => TRUE,
								  									  'default' => 0
								  									  ),
								  					'primary key' => array(
								  										  'nid', 'uid'
								  										  ),
								  					)
								  );
								  
	return $schema;
	
}

I checked if I had made some syntax error, but no there aren't, when I activate my module Drupal says that it's done, no error but no table ..

Anyone knows what I did wrong here?

Thanks!

Comments

Jaypan’s picture

Database tables are only installed on first install, not when modules are enabled. You need to disable the module, click the uninstall tab, uninstall the module, then reinstall it. Then your tables will be installed.

Yaeko-1’s picture

Ah okay, didn't knew that when deactivating the module, the module is in fact still installed.

I'll check it out :), thanks

theWasp’s picture

I have the same problem. But it doesn't help reenabling the module. Still no tables are created. Any experience with usual things that goes wrong?

chetan-singhal’s picture

1. most time people forget to return $schema variable
2. If module is alredy installed then reinstalled. Generally people reenable only.

chetan