Content Hub Tip #21: Remove unique qualifier of member

Content Hub Logo

We all have that moment when you think something is a really good idea at some point in time, to only learn later that you should not have done that. If not, then you're either really good at your job or just lack some experience.

One thing, I came across was the following problem. We had made a field in the past and forced the schema that the value must be unique. At first, this looked good and no one found this a problem. To later realise that it should not be unique.

Unque field

Ok, what now?
The first thing I thought of, was to create a temporary field and copy over the data to that temporary field. Then I could remove the unique field, don't forget to Apply changes to the schema, and recreate the field. Then we could copy back the temporary value to the newly created field and voila the data is back!

This sounds great when you only have one environment. If you have a multistage environment, this will not work. You can't create fields on separate instances, because the identifier will not be the same.

How can we fix this?
Well, Sitecore has got our back. We don't need to create a temporary field. Just do the following steps:
  1. Delete the field that you no longer to be unique
  2. Apply changes, this is important, otherwise, the schema will fail. It still has a reference to the name. And trust me, that's a good thing!
  3. Then recreate the field with the same name and type
  4. Apply changes once more
  5. Et voila, the values are back. It's like magic ;)
Remark: I haven't tested this with changes in the field type from a string to date for instance. Also changing from not unique to unique, could cause problems. You then need to make sure that the data is unique before you try to undertake such an action.

I hope this tip will save you a lot of time in the future.

Until next time!