I plan to add a table using hook_schema. I defined the circuit and call it in my module. However, no schema is created. Where am I going wrong. I have the following code in sample2.install file
function sample2_schema(){ $schema['mytable1'] = array( 'description' => t('My table description'), 'fields' => array( 'mycolumn1' => array( 'description' => t('My unique identifier'), 'type' => 'serial', 'unsigned' => true, 'not null' => true, ), 'myvarchar' => array( 'description' => t('My varchar'), 'type' => 'varchar', 'length' => 32, 'not null' => true, ), 'mytimestamp' => array( 'description' => t('My timestamp'), 'type' => 'int', 'not null' => true, ), ), 'indexes' => array( 'myvarchar' => array('myvarchar'), ), 'primary key' => array('mycolumn1'), 'unique keys' => array( 'mycolumn1' => array('mycolumn1'), ), ); return $schema; } function sample2_install(){ drupal_install_schema('sample2'); } function sample2_uninstall(){ drupal_uninstall_schema('sample2'); }
To call it, I use the following code in the sample2.module file.
$record = (object) NULL; $record->myvarchar = 'blah'; $record->mytimestamp = strtotime('now'); drupal_write_record('mytable1',$record);
This does not create any table.
source share