function _update_7000_field_delete_field

Deletes a field stored in SQL storage directly from the database.

To protect user data, this function can only be used to delete fields once all information it stored is gone. Delete all data from the field_data_$field_name table before calling by either manually issuing delete queries against it or using _update_7000_field_delete_instance().

Parameters

$field_name: The field name to delete.

Related topics

File

drupal/core/modules/field/field.install, line 253
Install, update, and uninstall functions for the Field module.

Code

function _update_7000_field_delete_field($field_name) {
  $table_name = 'field_data_' . $field_name;
  if (db_select($table_name)
    ->range(0, 1)
    ->countQuery()
    ->execute()
    ->fetchField()) {
    $t = get_t();
    throw new Exception($t('This function can only be used to delete fields without data'));
  }

  // Delete all instances.
  db_delete('field_config_instance')
    ->condition('field_name', $field_name)
    ->execute();

  // Nuke field data and revision tables.
  db_drop_table($table_name);
  db_drop_table('field_revision_' . $field_name);

  // Delete the field.
  db_delete('field_config')
    ->condition('field_name', $field_name)
    ->execute();
}