Cannot change a field from "String" to "DateTime"

I have…

  • [x] Checked the logs and have uploaded a log file and provided a link because I found something suspicious there. Please do not post the log file in the topic because very often something important is missing.

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [x] Bug report
  • [ ] Performance issue
  • [x Documentation issue or request

Current behavior

When you change a field json from

        {
        "name": "lastModifiedDate",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": true,
            "fieldType": "String",
            "createEnum": false,
            "editor": "Input",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "contentType": "Unspecified",
            "label": "Last Modified Date",
            "hints": "",
            "placeholder": ""
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },

to

    {
        "name": "lastModifiedDate",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": true,
            "fieldType": "**DateTime**",
            "createEnum": false,
            "editor": "**DateTime**",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "contentType": "Unspecified",
            "label": "Last Modified Date",
            "hints": "",
            "placeholder": ""
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },

and press synchronize schema it states there have been no changes.

Expected behavior

That the field type is changed and the different editor is used. Or even just the different editor type is used and the data is kept as a validated string

Environment

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [x] Cloud version

Version: [VERSION]

Browser:

  • [ ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Others:

When you change the type, it only works when you recreate the fields. There should be a checkbox for that. This basically deletes the field and creates a new one.

I assume the data would be lost in this case? It be good to inform the user that there are changes and that they won’t be done due to the type change

No, data is only lost if it does not match to the schema anymore.

e.g. if a field has type “DateTime” and the value is 'foobar" it does not match and the value is not returned. This is done at query time.

Yes, the json editor could be improved, but it is a very special feature anyway.

Would an ISO date work properly?

Yes, it must be ISO 8601…like the “normal” format for JSON datetimes.

Just an update for future people if they have this problem.

We did not like the recreate fields button as we had never used it before and did not know what other fields might be recreated during this process.

We migrated all the data to ISO date formats before we knew that we could not change the field type. We then decided to delete the string field and make a new field with the same name and DateTime type/editor and intended to manually migrate the data into the relevant records. Much to my surprise when the new field was created the correctly formatted data was already there which saved us allot of manual entry!

1 Like

Thanks a lot for your update.

I just want to add one thing: The schema is not like a SQL database schema that enforces the structure of your data. If you delete a field in SQL the data is gone forever. But a Squidex schema is more like a JSON schema and describes the nature of the documents in the database. Therefore if your schema matchs to the data at query time, everything is fine. So if you delete a field and recreate it in works fine. To ensure that invalid data is not sent to the client, there is a validation process in the query code, which usually just checks the type of the value:

1 Like