3

I'm using a custom decimal field in a custom product type in Drupal commerce. It has a precision of 10 and a scale of 2 (2 digits to the right of the decimal place).

I have a client with a large number of products that use this field, but their specification has now changed to require a decimal to 3dp.

By default Drupal "locks" the field to avoid data loss:

Because the field already has data, some settings can no longer be changed.

I took to editing the database, and it seems to have worked fine. I did three things:

  1. Changed the structure type of field_THIS_FIELD_value field in the drupal_field_data_THIS_FIELD table from decimal(10,2) to decimal(11,3)

  2. Repeated the same for the field revision table

  3. I downloaded the BLOB from table 'drupal_field_config' for field_THIS_FIELD and altered {s:9:"precision";s:2:"10";s:5:"scale";s:1:"2" to {s:9:"precision";s:2:"11";s:5:"scale";s:1:"3"

I cleared cache and existing data now has an extra 0 after the decimal place, and when I alter the data it stores it to 3 decimal places.

So it seems to work fine. But am I missing anything? Is there anywhere else where field data is changed that I might need to change?

Does the system integrity remain intact? I think I've done what's necessary but don't want to inadvertently break something else or cause any weakness in the system.

3
  • OK I created a new instance to check the BLOB in drupal_field_config_instance matched the existing one. Anything else? Oct 21 '15 at 10:53
  • FYI my action plan worked fine. May 31 '16 at 23:23
  • Hi, this could be related to my need : drupal.stackexchange.com/questions/231596/… Could you explain how to replace the updated blob file ( editor, transfer..) ? thanks Mar 20 '17 at 8:01
0

you could create a new field with the settings you need and import the data from the old field. see: https://www.drupal.org/node/1491590#comment-9682599

2
  • Hey Ahmed, don't want to do that as there is a lot of data and field is linked with modules. My solution seems to work, so question really is whether it's adequate and if I have overlooked anything. Oct 21 '15 at 10:54
  • Ok, I think the doc is missing in drupal, "what changes have to be made" if you want to change field settings after data has been filled in Oct 21 '15 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.