dgraph-io/dgraph · error

Cannot load into namespace %#x. It does not exist.

Error message

Cannot load into namespace %#x. It does not exist.

What it means

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.

Source

Thrown at dgraph/cmd/live/run.go:756

		MaxRetries:    math.MaxUint32,
		bufferSize:    opt.bufferSize,
	}

	// Create directory for temporary buffers.
	x.Check(os.MkdirAll(opt.tmpDir, 0700))

	dg, closeFunc := x.GetDgraphClient(Live.Conf, true)
	defer closeFunc()

	l := setup(bmOpts, dg, Live.Conf)
	if err := l.populateNamespaces(ctx, dg, singleNsOp); err != nil {
		fmt.Printf("Error while populating namespaces %s\n", err)
		return err
	}

	if !opt.preserveNs {
		if _, ok := l.namespaces[opt.namespaceToLoad]; !ok {
			return errors.Errorf("Cannot load into namespace %#x. It does not exist.",
				opt.namespaceToLoad)
		}
	}

	if len(opt.schemaFile) > 0 {
		err := l.processSchemaFile(ctx, opt.schemaFile, opt.key, dg)
		if err != nil {
			if err == context.Canceled {
				fmt.Printf("Interrupted while processing schema file %q\n", opt.schemaFile)
				return nil
			}
			fmt.Printf("Error while processing schema file %q: %s\n", opt.schemaFile, err)
			return err
		}
		fmt.Printf("Processed schema file %q\n\n", opt.schemaFile)
	}

	if l.schema, err = getSchema(ctx, dg, rootNsOperation); err != nil {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Verify the namespace exists via /state endpoint or `curl alpha:8080/state` and use a valid namespace ID with --force-namespace
  2. Create the target namespace first (e.g. via /multitenancy/addnamespace admin API) before running live
  3. Add --preserve-ns if the data files carry their own namespaces and you want them loaded as-is
  4. Point the loader at the correct Alpha address for the cluster that owns the namespace

Example fix

// before
dgraph live --force-namespace 0x5 -f data.rdf   # namespace 0x5 does not exist
// after
curl -X POST http://alpha:8080/multitenancy/addnamespace   # create namespace 0x5
dgraph live --force-namespace 0x5 -f data.rdf
Defensive patterns

Strategy: validation

Validate before calling

// Check that the target namespace exists before running dgraph live
const state = await (await fetch('http://alpha:8080/state')).json();
const nsId = '0x5';
if (!(nsId in (state.namespaces ?? {}))) {
  throw new Error(`Namespace ${nsId} does not exist on the cluster`);
}

Type guard

function namespaceExists(clusterState, nsHex) {
  return Object.prototype.hasOwnProperty.call(clusterState?.namespaces ?? {}, nsHex);
}

Try / catch

try {
  await runLive({ forceNamespace: nsId, files });
} catch (e) {
  if (String(e.message).includes('does not exist')) {
    console.error(`Create namespace ${nsId} first or use --preserve-ns`);
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/145c1beeaf4e9a02. Report an issue: GitHub.