How does one remove a field from a node programmatically? I have a migration in hook_update_N
that moves the contents from a a field into a custom table. After that migration, I want to remove the field in that same function.
Are there any field API's that cater removing fields?
Edit, Solution: Because the answers lack actual code, here is what I did to move fields from the $users into my own records and subsequently remove the field from the database;
function my_module_update_7005(&$sandbox) {
$slice = 100;
//Fetch users from database;
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_uid'] = 0;
// We'll -1 to disregard the uid 0...
$sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1;
}
if (empty($users)) {
$sandbox["current_uid"] += $slice;
}
$users = db_select('users', 'u')
->fields('u', array('uid', 'name'))
->condition('uid', $sandbox['current_uid'], '>')
->range(0, $slice)
->orderBy('uid', 'ASC')
->execute();
//Loop trough users;
foreach ($users as $user) {
$foo = new Foo();
// Warning: drupal's fields return mixed values; e.g. NULL versus an int.
$foo->debits = (int) $user->user()->field_credits["und"][0]["value"];
$foo->save();
$sandbox['progress']++;
$sandbox['current_uid'] = $user->uid;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
// Remove the field.
field_delete_field("field_credits"); //note that the name for Foo is field_foo
field_purge_batch($sandbox['max']+1);//Drupal seems to have an offbyone problem.
}