Hi,

I'm having some troubles with the hook_schema and hook_install.
So I want to create a table when activating my module. Seems that it's not working very well.

I don't get any errors when activating the module, but I don't get the defined table in my database.
If someone could check with I'm doing wrong?

Code in my .install file:

<?php

/*
 * Implements hook_schema()
 */
function fb_recommend_schema(){
	$schema['fb_recommend'] = array(
		'fields' => array(
			'id' => array(
				'description' => 'The ID',
				'type' => 'int',
				'size' => 'big',
				'not null' => TRUE,
			),
			'url' => array(
				'description' => 'The url that is needed to show the facebook recommend box',
				'type' => 'text',
				'size' => 'normal',
			),
				'not null' => TRUE,
			'width' => array(
				'description' => 'The width of the facebook recommend box',
				'type' => 'int',
				'size' => 3,
				'not null' => TRUE,
			),
			'height' => array(
				'description' => 'The height of the facebook recommend box',
				'type' => 'int',
				'size' => 3,
				'not null' => TRUE,
			),
		),
		'primary_key' => array('id'),
	);
	
	return $schema;
}

/*
 * Implements hook_install()
 */
function fb_recommend_install(){
	drupal_install_schema('fb_recommend');
}


/*
 * Implements hook_uninstall()
 */
function fb_recommend_uninstall(){
	drupal_uninstall_schema('fb_recommend');
}

Thanks!

Comments

nevets’s picture

Was the .install file present when you initially installed the module, if not you need to disable, uninstall then re-enable the module.

Also, _install and _uninstall are no longer required in Drupal 7.

Anonymous’s picture

The primary key field should be labelled 'primary key', not 'primary_key'. Not sure if that's why it's not working. Also remove the calls to drupal_install_schema and drupal_uninstall_schema as the schema is added automatically without them

Yaeko-1’s picture

ah damn yes, now I see, my module was installed, but I just disabled it, forgot to 'really' uninstall it.

Will check this. Thanks guys!