Score:0

Is it possible to convert a text field to an email type field that has exiting data in Drupal 9?

ng flag

We have a Drupal 9 site that has a plain text field with existing data that was used for email data. We'd like to convert this field type to email. Is this possible?

cn flag
Does this answer your question? [How do I move content from one field to another?](https://drupal.stackexchange.com/questions/197244/how-do-i-move-content-from-one-field-to-another)
cn flag
In this case, the easiest way is to create a new field of the email type and then move the data over. If you try to convert the field manually, many bad things will happen; it's much easier to create a new field and move your data to that, then delete the old field.
quantumized avatar
ng flag
That page's info seems to be for D7 and is for moving data to a new field, not converting an existing field's type. Thank you though.
cn flag
Generally you cannot convert field types without high risk of something going wrong. So this is the same approach you want to take in Drupal 9-- create a new field, and copy the data over.
jbarrio avatar
cn flag
Patrick is right. You will find it easy to just create a new field and copy data into it. If your concern is about the machine name, you can do it in a 2-steps process: 1) rename text field to something different; 2) create new field using old machine name & copy data into it. On the other side, as they are just configuration, have you tried to do a drush cex, change the field type and then do a drush cim?
quantumized avatar
ng flag
Thank you guys - I'll create the new field and migrate the data.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.