I have implemented php code to update a field from integer to decimal. However when trying to modify the field name from UI, it gives error:
Attempt to update field Maximum Temperature failed: field_sql_storage cannot change the schema for an existing field with data.
The system behaves well when editing existing field data or creating a new one.
Please find the code executed via hook_update_N() below:
/**
* Modify the integer field of nursing notes temperature field
* to decimal field with precision and scale
*/
function ji_custom_update_7001() {
// Manual database changes.
db_query("UPDATE {field_config} SET type = 'number_decimal'
WHERE field_name = 'field_nursing_note_max_temp'");
$new_field = array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
);
db_change_field('field_data_field_nursing_note_max_temp', 'field_nursing_note_max_temp_value'
, 'field_nursing_note_max_temp_value', $new_field);
db_change_field('field_revision_field_nursing_note_max_temp', 'field_nursing_note_max_temp_value'
, 'field_nursing_note_max_temp_value', $new_field);
// Clear caches.
field_cache_clear(TRUE);
}