2

I need to change one of the fields of a type of a node from a free-form text to be a taxonomy term, but the data already has about 250,000 records.

How can I change this field type without losing the existing data?

  • You can't change it in place; you'll probably need to write a script to convert the existing values to taxonomy terms, keeping an index of entity id and term id as you go so you use it to populate data later. Then delete the field, re-create it as a taxonomy reference, load up the relevant entities, attach the data from your index, and save them. Not a 5 minute job really – Clive Nov 13 '15 at 18:48
4

Changing the field type as you asked is not possible.

However a possible alternative to achieve a similar result is like so (in the order specified):

  • Create a new taxonomy term field, so that "from now on" any future node updates (or new nodes being created) will use that new field.
  • Use the Rules module to create a rule like so:
    • Rules event: before saving content.
    • Rules conditions:
      • entity has field, with field = the old field.
      • AND NOT (entity has field, with field = the new field).
    • Rules Action: set Drupal message, which contains some instructions that the old field must be blanked out, and the new field should contain the appropriate value(s.

Obviously, this approach will take "some" time if this has to be done manually, 1 node at a time. But using Views (to build a list of similar nodes to be updated) and VBO (to mass update such lists) you might (should!) be able to speed up this process quite a bit. Refer to my answer to "How to bulk update select list fields?" for an example with way more details about that.

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.