{"record":{"id":"14c93a98eafee52f","repo":"hasura/graphql-engine","slug":"applying-metadata-w","errorCode":null,"errorMessage":"applying metadata: %w","messagePattern":"applying metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/pkg/metadata/mode_handlers.go","lineNumber":265,"sourceCode":"\t\t)\n\t}\n\n\tif p.ec.Config.Version == cli.V2 {\n\t\tr, err := cli.GetCommonMetadataOps(p.ec).\n\t\t\tReplaceMetadata(bytes.NewReader(localMetadataBytes))\n\t\tif err != nil {\n\t\t\treturn nil, errors.E(op, err)\n\t\t}\n\n\t\treturn r, nil\n\t}\n\n\tr, err := p.ec.APIClient.V1Metadata.V2ReplaceMetadata(hasura.V2ReplaceMetadataArgs{\n\t\tAllowInconsistentMetadata: true,\n\t\tMetadata:                  metadata,\n\t})\n\tif err != nil {\n\t\treturn nil, errors.E(op, fmt.Errorf(\"applying metadata: %w\", err))\n\t}\n\n\tb := new(bytes.Buffer)\n\tif err := json.NewEncoder(b).Encode(r); err != nil {\n\t\treturn nil, errors.E(op, fmt.Errorf(\"encoding json response from server: %w\", err))\n\t}\n\n\treturn b, nil\n}\n\nfunc export(p *ProjectMetadata, mode cli.MetadataMode) (io.Reader, error) {\n\tvar op errors.Op = \"metadata.export\"\n\n\tmetadata, err := p.ec.APIClient.V1Metadata.ExportMetadata()\n\tif err != nil {\n\t\treturn nil, errors.E(op, fmt.Errorf(\"exporting metadata from server: %w\", err))\n\t}\n","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/pkg/metadata/mode_handlers.go#L247-L283","documentation":"This is the core server-side failure in metadata apply: the CLI successfully read and parsed local metadata, then called V2ReplaceMetadata on the Hasura server (with AllowInconsistentMetadata: true) and the server returned an error. The wrapped error text from the GraphQL API usually describes the real problem, e.g. unknown table, inconsistent objects, or permission denied.","triggerScenarios":"Calling Apply when the metadata references database tables/relationships/permissions that do not exist on the target server's configured databases; when the Hasura version does not support fields present in the metadata; or when the endpoint/admin secret are wrong (auth errors surface here too since the request reached the API layer).","commonSituations":"Applying metadata exported from an environment whose database schema differs from the target; applying v2 metadata to an incompatible server version; missing env var substitutions so table names resolve incorrectly; wrong HASURA_GRAPHQL_ADMIN_SECRET causing 401 from the metadata API.","solutions":["Read the wrapped server error message — it names the offending object (table, relationship, action, etc.)","Ensure the target database schema matches the metadata (run/apply migrations first, then metadata)","Verify the server endpoint and admin secret/env vars used by the CLI are correct and the Hasura version is compatible with the metadata version","Remove or fix the inconsistent objects the server complains about, then re-apply"],"exampleFix":"# before\nhasura metadata apply  # applying metadata for table \"users\" that target DB lacks\n# after\nhasura migrate apply     # create the schema first\nhasura metadata apply","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go: inspect errors.Is/As on the wrapped API error\nif _, err := pm.Apply(ctx, mode); err != nil {\n    var msg string\n    if errors.As(err, &hasuraErr) { msg = hasuraErr.Message }\n    // branch on 'inconsistent metadata' vs auth vs connectivity\n}","preventionTips":["Always apply migrations before metadata in CI pipelines","Keep database schemas in sync across environments before applying metadata","Pin CLI and server versions together and test upgrades on a staging project"],"tags":["metadata","graphql-api","server-error","hasura","inconsistent-metadata"],"backgroundTag":"metadata-apply-rejected","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}