Contentful logo

Contentful Community

Convert integer field to decimal

Hi,
Is there any way to convert an already existing field (in production with a lot of content) from integer to decimal?
We need decimal support but there seems to be no way to change this once created.

It isn’t possible to change the field type once created. But what you could do is to add a new field for decimals and gradually migrate the content:

  1. In the Web App, create a new ‘Number’ > ‘Decimal’ field (same name of the existing field with appended ‘_decimal’)
  2. Use our Migration-CLI, and specifically transformEntries to copy the field contents to the new field:
    https://github.com/contentful/contentful-migration/blob/master/README.md#transformentriesconfig
  3. If you don’t want to delete the existing integer field right away, you could think of using a UI-extension to update the new decimal field whenever the integer field is modified:
    https://www.contentful.com/developers/docs/extensibility/ui-extensions/
    https://github.com/contentful/extensions/tree/master/samples/slug
  4. Once you are sure that the content is migrated, you should also remember to adapt your Frontend. Therefore you will need to disable the ‘integer’ field from the response in the Content-type editing
  5. After some time, if everything works correctly, you can then finally delete the ‘integer’ field from your Content-type