Confusing validations error from the Migrations CLI

Hi There!

I’m attempting to run a pretty straightforward migration script to update a validations field for a Content Type. However, when I run the migration I get the following error:

Error: {"status":"Unprocessable Entity","message":"Validation error","details":{"errors":[{"name":"validationDefined","details":"Array fields do not support \"linkContentType\" validations","value".....

as well as:

Error: {"status":"Conflict","message":"","details":{},"url":"https://api.contentful.com:443/spaces/(redacted space id)/content_types/campaign/published"}

I was following the validation instructions from this document.

Here’s how the migrations script looks:

module.exports = function (migration) {
  const campaign = migration.editContentType('campaign');

  campaign.editField('quizzes')
    .validations([{
      linkContentType: [
        'quizBeta', 'quiz'
      ],
    }]);
}

Any insight would be appreciated!
Thanks so much in advance!

Hey @mblesofsky,

would you be able to share the current JSON representation of the field you want to update, so we can understand better what is going on?

Best,
Stephan

Sure @stephan.schneider ! Sorry for the delay.

Here’s how the field looks:

{
      "id": "quizzes",
      "name": "Quizzes",
      "type": "Array",
      "localized": false,
      "required": false,
      "validations": [],
      "disabled": false,
      "omitted": false,
      "items": {
        "type": "Link",
        "validations": [
          {
            "linkContentType": [
              "quiz",
              "quizBeta"
            ]
          }
        ],
        "linkType": "Entry"
      }
    },

I did end up adding that validation manually. Previously the linkContentType only allowed quizBeta. My migration script was attempting to update that validation to include quiz as well.

Ah I see - we don’t have any DSL in place yet that tracks down the type of a field when updating a field property.

So usually validations is a legit property that can be assigned to any field except arrays. Here we have to assign it on the items sub-key.

For now your best bet is to do the following:

module.exports = function (migration) {
  const campaign = migration.editContentType('campaign');

  campaign.editField('quizzes')
    .items({
      type: 'Link',
      linkType: 'Entry',
      validations: [{
        linkContentType: [
          'quizBeta', 'quiz'
        ],
      }]
    });
}

Please not that this replaces the whole items object, so you need to state properties like type again. This is less than optimal, but should unblock you for now.

Best,
Stephan

1 Like

Ah I see, I’ll give this a go.

Thanks so much for your help @stephan.schneider!

(EDIT: This did indeed work splendidly!)