dgraph-io/dgraph · error

Cannot delete default namespace

Error message

Cannot delete default namespace

What it means

resolveDeleteNamespace refuses to delete namespace 0 (x.RootNamespace), the built-in 'galaxy' default namespace that Dgraph uses for its own administrative data. Any deleteNamespace request whose resolved NamespaceId equals the root namespace is rejected outright with this fixed message. This is an intentional safety guard, not a runtime failure.

Source

Thrown at graphql/admin/namespace.go:59

	}
	return resolve.DataResult(
		m,
		map[string]interface{}{m.Name(): map[string]interface{}{
			"namespaceId": json.Number(strconv.Itoa(int(ns))),
			"message":     "Created namespace successfully",
		}},
		nil,
	), true
}

func resolveDeleteNamespace(ctx context.Context, m schema.Mutation) (*resolve.Resolved, bool) {
	req, err := getDeleteNamespaceInput(m)
	if err != nil {
		return resolve.EmptyResult(m, err), false
	}
	// No one can delete the galaxy(default) namespace.
	if uint64(req.NamespaceId) == x.RootNamespace {
		return resolve.EmptyResult(m, errors.New("Cannot delete default namespace")), false
	}
	if err = (&edgraph.Server{}).DeleteNamespace(ctx, uint64(req.NamespaceId)); err != nil {
		return resolve.EmptyResult(m, err), false
	}
	dropOp := "DROP_NS;" + fmt.Sprintf("%#x", req.NamespaceId)
	if err = edgraph.InsertDropRecord(ctx, dropOp); err != nil {
		return resolve.EmptyResult(m, err), false
	}
	return resolve.DataResult(
		m,
		map[string]interface{}{m.Name(): map[string]interface{}{
			"namespaceId": json.Number(strconv.Itoa(req.NamespaceId)),
			"message":     "Deleted namespace successfully",
		}},
		nil,
	), true
}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Pass a non-zero namespace in the input: { deleteNamespace(input: { namespace: 123 }) }.
  2. Verify which namespace you actually intend to drop (use /state or the queryRootNamespace API) — never 0.
  3. If the goal is to wipe data in the default namespace, use drop operations (DropData/DropAll) within namespace 0 instead of deleting the namespace.
  4. Guard automation code to skip/error before calling the mutation when id == 0.

Example fix

// before
mutation { deleteNamespace(input: { namespace: 0 }) { response { message } } }
// after
mutation { deleteNamespace(input: { namespace: 42 }) { response { message } } }
Defensive patterns

Strategy: validation

Validate before calling

function assertDeletableNamespace(nsId) {
  if (nsId === 0 || nsId === '0' || nsId == null) {
    throw new Error('refusing to delete default (galaxy) namespace 0');
  }
  return nsId;
}

Type guard

function isDeletableNamespace(ns) { return ns != null && Number(ns) !== 0; }

Try / catch

try {
  await gql(deleteNamespaceMutation, { input: { namespace } });
} catch (e) {
  if (String(e.message).includes('Cannot delete default namespace')) {
    // choose the intended non-zero namespace; do not retry with 0
  }
}

Prevention

When it happens

Trigger: Invoking the deleteNamespace admin mutation with namespace omitted (defaults to root namespace 0) or explicitly set to 0.

Common situations: Operators writing scripts to clean up test namespaces without realizing the default/galaxy namespace can never be deleted; clients omitting the optional namespace argument and silently defaulting to 0; automation reading namespace IDs from config where 0 is a placeholder value.

Related errors


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