Try our conversational search powered by Generative AI!

Field type change


we are trying to change property type from  ContentReference to IList<ContentReference> is there any way to do that in-place or do we need to create a new field and migrate the data?

Mar 22, 2022 13:54

I think you'll need to create a new property and migrate the data.

You could have a look at MigrationStep but I'm not sure it can be used here...

Apr 04, 2022 5:49

Thomas is right in suggesting the use of MigrationStep, I've used it to create and mutate content items on site start up.  The great part is that they execute once per environment.  You'd have to use the IContent Repository to mutate your old field values onto your new fields and you'd have to iterate over all of your content items with some form of recursive lookup.  I would advise then when you save a content item within a MigrationStep that you use the following save command:

contentRepository.Save(writeablePage, SaveAction.Patch, AccessLevel.NoAccess);

SaveAction.Patch will bypass any validation errors when updating the content.  During a migration step you won't want validation errors to prevent you from converting the field.  The AccessLevel.NoAccess prevents the save event from needing a user with specific privileges to be the person triggering the save event.

An alternative tactic would be to retain both fields and use a method to access them.  If the IList<ContentReference> field is null or empty then fall back to the old ContentReference.  In the interim you could specify that the old version of the field should not be editable by decorating it with:

Apr 05, 2022 14:02

I think it is strange because it seems to only be the case for some data types. I changed a property of type int to string and it worked perfectly fine in the cms

Jun 20, 2023 11:42
Tim Schmelter - May 06, 2024 17:31
How did you manage that type change? I get an InvalidCastException on initialization of the cms. So it seems that as soon there is data, you cannot change the type. But while an empty property value worked locally with the new type string, it failed on the other environments. Our cms is 12
Laurent - May 08, 2024 7:43
This was a year ago. I was playing around in Alloy Demo. Have not been able to recreate it

Hi Laurent,

It will be down to the compatability of the fields when swapping out the types.  Int to String isn't really a biggy.  However ContentReference to IList<ContentReference> can be much more complicated.

IList<ContentReference> goes into the [tblContentProperty].[LongString] field as such:


ContentReference goes into [tblContentProperty].[LinkGuid] as such


In this scenario a transformation has to take place as the value won't translate, one is essentially a string array while the other is a UID.

Jun 20, 2023 13:01
Laurent - Jun 20, 2023 13:04
I see! Thank you Mark! Its cool to learn more about how they are persisted in the database
Mark Stott - Jun 20, 2023 13:09
You're welcome :) I had to double check my information and write some queries first :D
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.