I am developing a small module and when I go to install it my .install (file) fails to create the table in the database. When I use the Schema tool, it shows Missing (1) and the detail states "Tables in the schema that are not present in the database."

If I then reinstall the module using devl's reinstall module, the table will get created. I have spent much time working on this error and I can repeatedly recreate it. I have broken down my .install code into smaller pieces and repeatedly recreated the file from scratch, all to no avail.

Has anyone every since a problem like this ? Is there any way to determine why the table is not getting created.?

Note: I can create and load other modules without this problem. I just can't see what is going wrong with this particular module.
I am running Drupal 6.5 and PHP 5.2.6. using XAMPP 1.6.8 running on Windows XP SP2.

Comments

mm167’s picture

why not post your .install file together with your question ...?

jackrobinson’s picture

<?php

// $Id$

/* @file
* ugcp module
*
*
* Implementation of hook_install().
*/

function ugcp_install() {
drupal_install_schema('ugcp');
}

function ugcp_uninstall() {
drupal_uninstall_schema('ugcp');
}
/**
* Implementation of hook_schema().
*/
function ugcp_schema() {
$schema['ugcp'] = array(
'description' => t("Stores data for nodes of type 'ugcp'."),
'fields' => array(
'nid' => array('description' => t("The ugcp's {node}.nid."),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => t("The ugcp's {node}.uid."),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => t('A Unix timestamp indicating when the Proposal was created.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'dept' => array(
'description' => t('Department or Program'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' => '',
),
'mailstation' => array(
'description' => t('mailstation'),
'type' => 'varchar',
'length'=>10,
'not null' => TRUE,
'default' => '',
),
'college_school' => array(
'description' => t('college or school'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' =>'',
),
'request_type' => array(
'description' => t('request type'),
'type' => 'varchar',
'length'=>20,
'not null' => TRUE,
'default' =>'',
),
'course_id' => array(
'description' => t('course id'),
'type' => 'varchar',
'length'=>9,
'not null' => TRUE,
'default' =>'',
),
'new_course_subject' => array(
'description' => t('new course subject'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' =>'',
),
'new_course_cat_number' => array(
'description' => t('new course catalog number'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' =>'',
),
'new_course_title' => array(
'description' => t('new course title'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' =>'',
),
'new_course_units' => array(
'description' => t('new course units'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' =>0,
),
'former_course_subject' => array(
'description' => t('former course subject'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' =>'',
),
'former_course_cat_number' => array(
'description' => t('former course catalog number'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' =>'',
),
'former_course_title' => array(
'description' => t('former course title'),
'type' => 'varchar',
'length'=>50,
'not null' => TRUE,
'default' =>'',
),
'former_course_units' => array(
'description' => t('former course units'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' =>0,
),
'catalog_description' => array(
'description' => t('catalog description'),
'type'=>'varchar',
'length'=> 50,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('nid'),
);
return $schema;
}

tilul’s picture

I am also encountering the same problem here... anybody help..?

tilul’s picture

ddd2500’s picture

I have the same problem in d7.

usescrt’s picture

I have the same problem too!

vj’s picture

dont use hook_install and hook_uninstall

here is my code for drupal 7


<?php
/**
 * @file
 * Install, update and uninstall functions for the notify module.
 */



function multipart_schema() {
 $schema['multipart'] = array(
    'descritption' => t('Stores information'),
    'fields' => array (
      'uid' => array (
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => t('User Id '),
      ),
      
      'notification_sent' => array (
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => t('Timestamp of notification'),
      ),
    ),
    'primary key' => array('uid'),
  );

  return $schema;
}
nicodv’s picture

...but still doesn't work. I tried to uninstall the module, clear caches, etc but no answer, the table doesn't appear in the db. Any clue?

thanks

THE VERY LITTLE AGENCY

jaypan’s picture

Can't help without code. Also, are you using D6 or D7?

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

nicodv’s picture


/**
 * @file
 * Install, update and uninstall tables for the myform module.
 */


/**
 * Implements hook_install().
 */
function myform_install() {
    //this function will run whenever the module s installed.
}

/**
 * Implements hook_uninstall()
 */
function myform_uninstall() {
}

/**
  * implements hook_schema().
  */
function myform_schema() {
  $schema['imacompany'] = array(
	'description' => 'A table to keep all the data from the custom data in the use',
	'fields' => array(
	  'coid' => array(
		'description' => 'The Id of the Im company field',
		'type' => 'serial',
		'unsigned' => TRUE,
		'not null' => TRUE,
	  ),
	  'imaco' => array(
		'description' => 'Tells us if the user is a company or not',
		'type' => 'int',
		'unsigned' => TRUE,
		'not null' => TRUE,
		'default' => 0,
	  ),
	),
	'primary key' => array('coid'),
	'indexes' => array(
	  'imaco' => array('imaco'),
	),
  );
  return $schema;
}


THE VERY LITTLE AGENCY

nicodv’s picture

My problem was that accidentally I was working on the .install file with the module activated. Then I tried to uncheck it from the list, clear caches etc but obviously was not enough for the core to consider it renewed and didn't apply the changes in my .install file.
I deactivated the module, I went to modules and in the 'uninstall' tab clicked my module, and then, install it back and it worked. As simple as that.

THE VERY LITTLE AGENCY

renegaed’s picture

Thanks so much for posting your solution. I had been disabling and enabling my module like mad after updating hook_schema() and Drupal simply refused to create my table. After disabling the module, uninstalling it (via the modules page) and then then enabling it again my table was finally created. Huzaah!