Migrating metafields to a definition
If you want to add validation rules to an existing set of metafields, then you can migrate your metafields to a definition. When you create a custom definition for existing sets of metafields, the validation rules that you specify prevent you or your apps from adding invalid values.
You migrate your metafields by creating a custom definition for a set of metafields with a particular namespace and key. After you create a definition, if any values for your existing metafields don’t match your definition, then you need to fix your metafield values.
You can only add definitions for sets of metafields that have a namespace and key with the correct format. If your namespace and key contains special characters, then you can't migrate that set of metafields to a definition.
Create a definition for sets of metafields that don't yet have a definition
- From your Shopify admin, go to Settings > Metafields.
- In the Manage metafields section, select the category that contains the metafield that you want to edit.
- On the Metafield definitions page, select the namespace and key that you want to create a definition for.
- Enter the following information for your metafield definition:
- In the Name field, enter a name for your definition.
- Optional: In the Description field, enter a description for your metafield.
- Click Select content type, and then select the content type that best matches your metafield values from the dropdown menu.
- Configure the content type and validation information:
- If the content type has additional configuration options, then select the correct option for your metafield. For example, type of measurement.
- In the Validation section, configure the Addional rules for your definition.
- If the content type has a Defaults section, then select a default unit.
- Click Save.
- Review the validation results, and then click Save and continue.
If any metafield values don’t match your new definition, then you need to fix your metafield values. After you save your definition, you're automatically redirected to the bulk editor to review and fix any validation errors.
After you add definitions for your metafields, you can do the following: