Changing content-type xml leaves ghost data after saving content

Enonic version: 6.9.2

Just wondering how data in the not existing fields should be handled.
When we remove a field in the content-type xml, the edit content form will no longer display the old field, but the data will still be in the content-viewer plugin, that’s ok. But when we click on “save draft”, the field data is still not removed from the content object. I’m not sure if deleting not existing fields from data on save should be done but it might be good to have a “raw data” editor to be able to remove garbage without importing and exporting, maybe adding a Content-Viewer plugin with an edit mode would be good? It would also help with quick copy-pasting of content between environments.

Also if you change a field type from say TextLine to ItemSet, then you can’t even edit the content anymore, cause the data is invalid.

I’ve heard rumours that best practice would be to have a updateData script to run in main.js and perhaps make use of major version, since changing xml structure is a “breaking” change.

The way I’ve worked around it before is versioning parts. And then deprecating the old part. The problem is you may end up with many many versions of the same part if no ones clean up the old data.

I think making multiple versions of a content-types makes even less sense.

Yeah removing old incompatible fields using contentLib query and modify in main.js shouldn’t be too difficult.

Like @cwe says, the solution is an upgrade script that fixes your old data. We have a backlog task providing a best practice for storing information about model number and running upgrade scripts. For now you would have to create and run this script once.