Skip to main content

Modify Integer field to Decimal

Submitted by amitsedai on
The purpose is to modify the integer field which captures temperature in decimal. A good way is to execute a hook_update_N() API in custom module which allows incremental updates when installing, or visiting update.php WARNING: Does not work. Its better to recreate field after copying data to another temp field. [ http://drupal.stackexchange.com/questions/103157/modifying-integer-field-to-decimal-gives-error-when-editing-field-information ] <?php /** * 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, ); // for changing field definition 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 the cache about fields information field_cache_clear(TRUE); } ?>

Technologies