I have constructed a module that, using the .install file, creates a table on a database different than the default. The module installs fine and functions fine – just a hello world example in the controller. However, when I uninstall the module I get: “The website encountered an unexpected error. Please try again later.” and the reports log there is: DatabaseExceptionWrapper: SQLSTATE[42S02]...
Here is the .install file code:
function hello_world_schema()
{
db_set_active('notTheDefaultDB');
$schema['create_table'] = array(
'fields' => array(
'id' => array('type' => 'serial', 'not null' => TRUE,),
'name' => array('type' => 'varchar', 'length' => 40, 'not null' => TRUE,),
'last_name' => array('type' => 'varchar', 'length' => 40, 'not null' => TRUE,),
'message' => array('type' => 'varchar', 'length' => 250, 'not null' => TRUE,),
'boogie' => array('type' => 'varchar', 'length' => 20, 'not null' => TRUE,),
),
'primary key' => array('id'),);
return $schema;
}
I do realize that I'm tell hook_schema to switch to notTheDefaultDB and don’t switch it back – if it is switched before the return statement the table is created in the default.
As I said, the module seems to function as intended, but blows up when uninstalled.
Is there a way to write the module so it doesn’t blow up on uninstall or perhaps an entirely different way to do what I’m after?