I'm trying to add a column to the 'users' table. When I install my module, the column gets created and when I uninstall it gets deleted.
The issue is that after I uninstalled, I run a 'drush cc all' and I receive this error:
WD php: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown[error] column 'base.firstname' in 'field list': SELECT base.uid AS uid, base.name AS name, base.pass AS pass, base.mail AS mail, base.theme AS theme, base.signature AS signature, base.signature_format AS signature_format, base.created AS created, base.access AS access, base.login AS login, base.status AS status, base.timezone AS timezone, base.language AS language, base.picture AS picture, base.init AS init, base.data AS data, base.firstname AS firstname FROM {users} base WHERE (base.uid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => 0 ) in DrupalDefaultEntityController->load() (line 193 of /var/www/includes/entity.inc).
Here is my code inside the .install:
function mymodule_schema_alter(&$schema) {
$schema['users']['fields']['firstname'] = array(
'type' => 'varchar',
'length' => 60,
'not null' => FALSE,
'default' => '',
'description' => 'Field added by profile common module',
);
}
function mymodule_install() {
$schema = drupal_get_schema('users');
db_add_field('users', 'firstname', $schema['fields']['firstname']);
}
function mymodule_uninstall() {
db_drop_field('users', 'firstname');
}
Thanks.
db_add_field()
logic in an update hook