{"record":{"id":"e095b5e7d24c1b13","repo":"vitessio/vitess","slug":"cannot-find-column-to-use-to-find-keyspace-id-for","errorCode":null,"errorMessage":"cannot find column to use to find keyspace_id for table %v","messagePattern":"cannot find column to use to find keyspace_id for table (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/binlog/binlog_streamer.go","lineNumber":498,"sourceCode":"\t\t\ttableMaps[tableID] = tce\n\n\t\t\t// Check we're in the right database, and if so, fill\n\t\t\t// in more data.\n\t\t\tif tm.Database != \"\" && tm.Database != bls.cp.DBName() {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Find and fill in the table schema.\n\t\t\ttce.ti = bls.se.GetTable(sqlparser.NewIdentifierCS(tm.Name))\n\t\t\tif tce.ti == nil {\n\t\t\t\treturn pos, fmt.Errorf(\"unknown table %v in schema\", tm.Name)\n\t\t\t}\n\n\t\t\t// Fill in the resolver if needed.\n\t\t\tif bls.resolverFactory != nil {\n\t\t\t\ttce.keyspaceIDIndex, tce.resolver, err = bls.resolverFactory(tce.ti)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn pos, fmt.Errorf(\"cannot find column to use to find keyspace_id for table %v\", tm.Name)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Fill in PK indexes if necessary.\n\t\t\tif bls.extractPK {\n\t\t\t\ttce.pkNames = make([]*querypb.Field, len(tce.ti.PKColumns))\n\t\t\t\ttce.pkIndexes = make([]int, len(tce.ti.Fields))\n\t\t\t\tfor i := range tce.pkIndexes {\n\t\t\t\t\t// Put -1 as default in here.\n\t\t\t\t\ttce.pkIndexes[i] = -1\n\t\t\t\t}\n\t\t\t\tfor i, c := range tce.ti.PKColumns {\n\t\t\t\t\t// Patch in every PK column index.\n\t\t\t\t\ttce.pkIndexes[c] = i\n\t\t\t\t\t// Fill in pknames\n\t\t\t\t\ttce.pkNames[i] = tce.ti.Fields[c]\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/binlog/binlog_streamer.go#L480-L516","documentation":"The resolverFactory callback for a table map entry must return a column index and resolver used to compute keyspace_id from row data. When it fails (e.g. the table's vindex or PK column cannot be resolved), parseEvents wraps the failure as this error naming the table.","triggerScenarios":"bls.resolverFactory is set and returns an error for the table in a TABLE_MAP event — typically because no usable column (PK or vindex-mapped column) exists to derive the keyspace_id during row streaming.","commonSituations":"Table has no primary key and no primary vindex configured; vindex definition missing or wrong in the vschema; legacy sharded keyspaces where the routing rules no longer match the streamed table.","solutions":["Ensure the table has a resolvable primary vindex or primary key columns in the vschema","Fix the resolverFactory configuration (routing rules / vindex mappings) so the table maps to a column","If the table needs no keyspace resolution (unsharded), configure the streamer so resolverFactory is not invoked for it","Inspect the underlying err from the factory (it is discarded by this wrap) by testing the factory directly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"ti := schemaEngine.GetTable(sqlparser.NewIdentifierCS(tableName))\nif ti == nil || len(ti.PKColumns) == 0 {\n    return fmt.Errorf(\"table %s has no PK/vindex column for keyspace_id\", tableName)\n}","typeGuard":null,"tryCatchPattern":"err := streamer.Stream(ctx, signals)\nif err != nil && strings.Contains(err.Error(), \"cannot find column to use to find keyspace_id\") {\n    // fix vschema vindex config, then restart stream\n}","preventionTips":["Give every streamed sharded table a primary vindex","Validate vschema before creating workflows","Keep resolverFactory/routing rules in sync with schema changes","Avoid PK-less tables in sharded streams"],"tags":["binlog","vindex","sharding"],"backgroundTag":"no-keyspace-id-column","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}