When I first developed this module internally (not on Druple.com) the module_schema
function created a table with the same name of the module (it was the only table, so it made sense. Short sighted.).
But I now need a 2nd table, so the first table should have a more sensible name. There is also a requirement for an additional field in the original table.
function afd_pce_update_dependencies(){
// update_7201 needs to run after update_7200.
$dependencies['mymodule_field_mappings'][7201] = array(
'mymodule_field_mappings' => 7200,
);
return $dependencies;
}
function mymodule_update_7200(){
db_rename_table('mymodule', 'mymodule_field_mappings');
}
function mymodule_update_7201(){
$spec = array(
'type' => 'varchar',
'description' => "The fieldset that this mapping belongs to",
'length' => 15,
'not null' => FALSE,
);
db_add_field('fieldset_type','mymodule_field_mappings',$spec);
}
When I run update.php
I get the error
Update #7201
Failed: DatabaseSchemaObjectDoesNotExistException:
Cannot add field <em class="placeholder">fieldset_type</em>.
<em class="placeholder">mymodule_field_mappings</em>: table doesn't exist.
in DatabaseSchema_mysql->addField() (line 325 of
{filepath}\includes\database\mysql\schema.inc).