I have an existing app-owned metafield definition that I need to change:
Current app metafield:
[product.metafields.app.hsn]
type = "number_integer"
name = "HSN Code"
description = "Harmonized System Nomenclature (HSN) code for product"
capabilities.admin_filterable = true
What I need:
[product.metafields.app.hsn]
type = "single_line_text_field"
name = "HSN Code"
description = "Harmonized System Nomenclature (HSN) code for product"
capabilities.admin_filterable = true
Reason for change:
We need to store HSN codes with leading zeros (e.g., “0101”, “0203”) but number_integer strips them (becomes 101, 203). The single_line_text_field type would preserve the leading zeros which are significant for HSN classification.
Problem:
When I update the metafield type in shopify.app.toml and run shopify app deploy, I get this error:
[product.metafields.app.hsn] Cannot change type of existing metafield definition - type: number_integer
What I’ve tried:
-
Removed the metafield from
shopify.app.tomland deployed - The metafield definition still exists in Shopify’s database, so I get the same error when trying to add it back with a different type -
Looked for it in Settings > Custom data - App-owned metafields (namespace: app) don’t appear in the Shopify admin UI, so I can’t delete it manually
-
Tried to find a CLI command - There doesn’t seem to be a shopify app config metafields delete command
Questions:
-
How do I delete an app-owned metafield definition? Is there a GraphQL mutation like
metafieldDefinitionDeletethat works for app metafields? -
Is changing metafield types supported at all? Or is the only option to create a new metafield key (e.g.,
app.hsn_code) and migrate data? -
If I need to use GraphQL to delete it, what’s the proper mutation? I tried finding the metafield definition ID but need confirmation this is the right approach for app metafields.
Environment:
-
App type: Remix app with Shopify Admin UI extensions
-
Metafield namespace: app (app-owned)
-
Current type:
number_integer -
Desired type:
single_line_text_field
Workaround I’m considering:
Create a new metafield app.hsn_code with single_line_text_field type, migrate existing data, then deprecate the old app.hsn metafield.
Is there a better way to handle this? Any help would be appreciated!