{"record":{"id":"145c1beeaf4e9a02","repo":"dgraph-io/dgraph","slug":"cannot-load-into-namespace-x-it-does-not-exist","errorCode":null,"errorMessage":"Cannot load into namespace %#x. It does not exist.","messagePattern":"Cannot load into namespace %#x\\. It does not exist\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/live/run.go","lineNumber":756,"sourceCode":"\t\tMaxRetries:    math.MaxUint32,\n\t\tbufferSize:    opt.bufferSize,\n\t}\n\n\t// Create directory for temporary buffers.\n\tx.Check(os.MkdirAll(opt.tmpDir, 0700))\n\n\tdg, closeFunc := x.GetDgraphClient(Live.Conf, true)\n\tdefer closeFunc()\n\n\tl := setup(bmOpts, dg, Live.Conf)\n\tif err := l.populateNamespaces(ctx, dg, singleNsOp); err != nil {\n\t\tfmt.Printf(\"Error while populating namespaces %s\\n\", err)\n\t\treturn err\n\t}\n\n\tif !opt.preserveNs {\n\t\tif _, ok := l.namespaces[opt.namespaceToLoad]; !ok {\n\t\t\treturn errors.Errorf(\"Cannot load into namespace %#x. It does not exist.\",\n\t\t\t\topt.namespaceToLoad)\n\t\t}\n\t}\n\n\tif len(opt.schemaFile) > 0 {\n\t\terr := l.processSchemaFile(ctx, opt.schemaFile, opt.key, dg)\n\t\tif err != nil {\n\t\t\tif err == context.Canceled {\n\t\t\t\tfmt.Printf(\"Interrupted while processing schema file %q\\n\", opt.schemaFile)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tfmt.Printf(\"Error while processing schema file %q: %s\\n\", opt.schemaFile, err)\n\t\t\treturn err\n\t\t}\n\t\tfmt.Printf(\"Processed schema file %q\\n\\n\", opt.schemaFile)\n\t}\n\n\tif l.schema, err = getSchema(ctx, dg, rootNsOperation); err != nil {","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/live/run.go#L738-L774","documentation":"The live loader verifies, after populating the namespace list from the Alpha, that the requested target namespace actually exists on the server. When preserve-ns is off and opt.namespaceToLoad is not present in the set of namespaces returned by the cluster, loading is refused because data would land in a non-existent namespace. This protects against typos and against loading into a fresh cluster that has not created the namespace yet.","triggerScenarios":"Running `dgraph live --force-namespace <id>` (or default namespace) where that namespace ID has never been created on the target Alpha; pointing live at the wrong cluster/env; loading a dump without --preserve-ns after the namespace metadata was not restored.","commonSituations":"Copying a load command between staging and production where namespace IDs differ; fresh cluster where only namespace 0 exists; dropping a namespace and re-running an old load script.","solutions":["Verify the namespace exists via /state endpoint or `curl alpha:8080/state` and use a valid namespace ID with --force-namespace","Create the target namespace first (e.g. via /multitenancy/addnamespace admin API) before running live","Add --preserve-ns if the data files carry their own namespaces and you want them loaded as-is","Point the loader at the correct Alpha address for the cluster that owns the namespace"],"exampleFix":"// before\ndgraph live --force-namespace 0x5 -f data.rdf   # namespace 0x5 does not exist\n// after\ncurl -X POST http://alpha:8080/multitenancy/addnamespace   # create namespace 0x5\ndgraph live --force-namespace 0x5 -f data.rdf","handlingStrategy":"validation","validationCode":"// Check that the target namespace exists before running dgraph live\nconst state = await (await fetch('http://alpha:8080/state')).json();\nconst nsId = '0x5';\nif (!(nsId in (state.namespaces ?? {}))) {\n  throw new Error(`Namespace ${nsId} does not exist on the cluster`);\n}","typeGuard":"function namespaceExists(clusterState, nsHex) {\n  return Object.prototype.hasOwnProperty.call(clusterState?.namespaces ?? {}, nsHex);\n}","tryCatchPattern":"try {\n  await runLive({ forceNamespace: nsId, files });\n} catch (e) {\n  if (String(e.message).includes('does not exist')) {\n    console.error(`Create namespace ${nsId} first or use --preserve-ns`);\n  } else { throw e; }\n}","preventionTips":["Query /state to enumerate namespaces before every scripted load","Create namespaces via the addnamespace admin API in setup scripts","Match namespace IDs between environments explicitly, never copy-paste"],"tags":["namespace","cli","configuration","cluster-state"],"backgroundTag":"namespace-not-found","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}