I have this entity:
$schema['apiuser'] = array(
'description' => 'The base table for api_user.',
'fields' => array(
'apiuser_id' => array(
'description' => 'The primary identifier for an artwork.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'public_key' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "Foreign key: {file_managed}.fid of user's picture.",
)
),
'unique keys' => array(
'id' => array('apiuser_id')
),
'primary key' => array('apiuser_id'),
);
Later I have added a new field:
,
$schema['apiuser'] = array(
'description' => 'The base table for api_user.',
'fields' => array(
'apiuser_id' => array(
'description' => 'The primary identifier for an artwork.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'public_key' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "Foreign key: {file_managed}.fid of user's picture.",
),
'user_id' => array(
'description' => 'The primary identifier for an artwork.',
'type' => 'int',
'not null' => TRUE,
)
),
'unique keys' => array(
'id' => array('apiuser_id')
),
'primary key' => array('apiuser_id'),
);
Drupal doesn’t change the respective table into mysql so I modified it manually. But now when I try to save the entity that new field is not filled. I have installed devel module and used ‘drush cc all’ to clear the cache, deactivated and activated the modeule but still doesn’t work
This is what the update script is for. You’ll want to write an update_N function, in which you can use the schema object to add your column:
Then run
http://yoursite.com/update.phpand drupal will modify your table accordingly.