Createfield() with default value

Hi! I’m making some migration scripts and I really need to set a default value for each field I’m creating I haven’t been able to find info of how to do it, this is what I got:

userAccess.createField(‘setPassword_title’, {
name: ‘Title’,
type: ‘Symbol’,
localized: true,
required: true,
validations: [],
disabled: false,
omitted: false
});

But I need something like value: ‘Default value’ do you have any ideas of how to do this ?

Hi there,
unfortunately it’s not possible to set default value when creating a new field in the migration CLI.
In order to set default value to a field, you will need to look into the Content Management API (CMA):
https://www.contentful.com/developers/docs/references/content-management-api/

Look at the example of transformEntries here https://www.contentful.com/developers/docs/tutorials/cli/scripting-migrations/

The from property can be an empty array if an existing field does not need to be used.

I have checked this on one of the latest version of Contentful CLI (1.9.31) and it worked for me. You don’t need management API now and can be done in migration script itself.
Documentation on how to add default value is here