{"record":{"id":"2b3abc5cd2287df0","repo":"vitessio/vitess","slug":"target-keyspace-not-defined-or-it-does-not-have-m","errorCode":null,"errorMessage":"target keyspace not defined, or it does not have multi-tenant spec","messagePattern":"target keyspace not defined, or it does not have multi-tenant spec","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/utils.go","lineNumber":845,"sourceCode":"\t\t\t\tRight: sel.Where.Expr,\n\t\t\t},\n\t\t}\n\t} else {\n\t\tsel.Where = &sqlparser.Where{\n\t\t\tType: sqlparser.WhereClause,\n\t\t\tExpr: filter,\n\t\t}\n\t}\n}\n\nfunc getTenantClause(vrOptions *vtctldatapb.WorkflowOptions,\n\ttargetVSchema *vindexes.KeyspaceSchema, parser *sqlparser.Parser,\n) (*sqlparser.Expr, error) {\n\tif vrOptions.TenantId == \"\" {\n\t\treturn nil, nil\n\t}\n\tif targetVSchema == nil || targetVSchema.MultiTenantSpec == nil {\n\t\treturn nil, errors.New(\"target keyspace not defined, or it does not have multi-tenant spec\")\n\t}\n\ttenantColumnName := targetVSchema.MultiTenantSpec.TenantIdColumnName\n\ttenantColumnType := targetVSchema.MultiTenantSpec.TenantIdColumnType\n\tif tenantColumnName == \"\" {\n\t\treturn nil, errors.New(\"tenant column name not defined in multi-tenant spec\")\n\t}\n\n\tvar tenantId string\n\tswitch tenantColumnType {\n\tcase querypb.Type_INT64:\n\t\t_, err := strconv.Atoi(vrOptions.TenantId)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"tenant id is not a valid int: %s\", vrOptions.TenantId)\n\t\t}\n\t\ttenantId = vrOptions.TenantId\n\tcase querypb.Type_VARCHAR:\n\t\ttenantId = sqltypes.EncodeStringSQL(vrOptions.TenantId)\n\tdefault:","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/utils.go#L827-L863","documentation":"getTenantClause builds a tenant-filtering SQL expression for VReplication queries when VReplicationOptions.TenantId is set. It requires the target keyspace's vschema to define a MultiTenantSpec. If the target keyspace has no vschema or lacks that spec, the tenant clause cannot be built and this error is returned.","triggerScenarios":"Running a VReplication operation with --tenant-id (vrOptions.TenantId non-empty) against a target keyspace whose vschema lacks `multi_tenant_spec` in its keyspace section, or when targetVSchema is nil (keyspace not found in vschema).","commonSituations":"Forgetting to add multi_tenant_spec to the target keyspace vschema before running a tenant-filtered MoveTables, misspelling the keyspace name so the vschema lookup returns nil, or using a workflow type that does not support tenant scoping.","solutions":["Add a multi_tenant_spec (with tenant_id_column_name and tenant_id_column_type) to the target keyspace's vschema and apply it (vtctldclient ApplyVSchema)","Verify the target keyspace name in the workflow matches the vschema entry exactly","Drop the --tenant-id flag if tenant filtering is not actually intended"],"exampleFix":"// before (vschema)\n{\"keyspaces\":{\"commerce\":{}}}\n// after\n{\"keyspaces\":{\"commerce\":{\"multi_tenant_spec\":{\"tenant_id_column_name\":\"tenant_id\",\"tenant_id_column_type\":\"INT64\"}}}}","handlingStrategy":"validation","validationCode":"ksVs, err := ts.TopoServer().GetVSchema(ctx, targetKeyspace)\nif err != nil || ksVs == nil || ksVs.MultiTenantSpec == nil {\n    return errors.New(\"target keyspace vschema must define multi_tenant_spec before using --tenant-id\")\n}","typeGuard":"func hasMultiTenantSpec(vs *vschemapb.Keyspace) bool {\n    return vs != nil && vs.MultiTenantSpec != nil\n}","tryCatchPattern":"expr, err := getTenantClause(vrOptions, targetVSchema, parser)\nif err != nil && errors.Is(err, errors.New(\"target keyspace not defined, or it does not have multi-tenant spec\")) {\n    return fmt.Errorf(\"apply multi_tenant_spec to %s vschema first: %w\", targetKeyspace, err)\n}","preventionTips":["Apply the multi-tenant vschema before starting tenant-scoped MoveTables","Validate the vschema JSON against the multi_tenant_spec schema","Double-check keyspace name spelling matches the vschema entry"],"tags":["vreplication","vschema","multi-tenant"],"backgroundTag":"missing-multitenant-spec","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}