{"record":{"id":"50478ac3c31647b5","repo":"vitessio/vitess","slug":"column-s-not-found-in-schema-v-50478a","errorCode":null,"errorMessage":"column %s not found in schema %v","messagePattern":"column (.+?) not found in schema (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/materializer.go","lineNumber":752,"sourceCode":"\tif targetVSchema.Sharded {\n\t\t// Choose a primary vindex type for target table based on source specs\n\t\tvar targetVindexType string\n\t\tvar targetVindex *vschemapb.Vindex\n\t\tfor _, field := range tableSchema.TableDefinitions[0].Fields {\n\t\t\tif sourceVindexColumns[0] == field.Name {\n\t\t\t\ttargetVindexType, err = vindexes.ChooseVindexForType(field.Type)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, nil, err\n\t\t\t\t}\n\t\t\t\ttargetVindex = &vschemapb.Vindex{\n\t\t\t\t\tType: targetVindexType,\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif targetVindex == nil {\n\t\t\t// Unreachable. We validated column names when generating the DDL.\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"column %s not found in schema %v\", sourceVindexColumns[0], tableSchema.TableDefinitions[0])\n\t\t}\n\t\tif existing, ok := targetVSchema.Vindexes[targetVindexType]; ok {\n\t\t\tif !proto.Equal(existing, targetVindex) {\n\t\t\t\treturn nil, nil, nil, fmt.Errorf(\"a conflicting vindex named %v already exists in the target vschema\", targetVindexType)\n\t\t\t}\n\t\t} else {\n\t\t\ttargetVSchema.Vindexes[targetVindexType] = targetVindex\n\t\t}\n\n\t\ttargetTable = &vschemapb.Table{\n\t\t\tColumnVindexes: []*vschemapb.ColumnVindex{{\n\t\t\t\tColumn: vindexFromCols[0],\n\t\t\t\tName:   targetVindexType,\n\t\t\t}},\n\t\t}\n\t} else {\n\t\ttargetTable = &vschemapb.Table{}\n\t}","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/materializer.go#L734-L770","documentation":"For a sharded target keyspace, Vitess picks a primary vindex type based on the source vindex column's MySQL type and must locate that column in the fetched table schema fields. If the column can't be found among the schema fields, preparation fails. The code marks this unreachable because columns are validated earlier, so it usually signals schema drift between validation and use.","triggerScenarios":"sourceVindexColumns[0] not present in tableSchema.TableDefinitions[0].Fields — e.g. the schema was altered between validation and target-vschema generation, or case-sensitivity mismatch between the vschema column name and the MySQL schema.","commonSituations":"Concurrent DDL renaming/dropping the column mid-command; vschema column spelled differently from the actual MySQL column; schema cache staleness on the tablet.","solutions":["Re-run CreateLookupVindex (transient schema-drift issues usually resolve)","Ensure the vschema ColumnVindex column name matches the actual MySQL column exactly (case included)","Reload tablet schema (`vtctldclient ReloadSchema`) if the schema was recently altered"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"tds, _ := schematools.GetSchema(ctx, ts, tmc, primaryAlias, req)\nfound := false\nfor _, f := range tds.TableDefinitions[0].Fields {\n    if f.Name == sourceVindexColumns[0] { found = true }\n}\nif !found {\n    return fmt.Errorf(\"vindex column %s missing from table schema\", sourceVindexColumns[0])\n}","typeGuard":"func schemaHasColumn(td *tabletmanagerdatapb.TableDefinition, col string) bool {\n    for _, f := range td.Fields { if f.Name == col { return true } }\n    return false\n}","tryCatchPattern":"if err := createLookupVindex(...); err != nil {\n    if strings.Contains(err.Error(), \"not found in schema\") {\n        return retryAfterSchemaReload(err) // transient drift: reload and retry\n    }\n    return err\n}","preventionTips":["Avoid concurrent ALTER TABLE on the vindex column while creating lookup vindexes","Keep vschema column names identical (case included) to MySQL column names","Reload tablet schema after any DDL before running materialization"],"tags":["vitess","schema","column-not-found"],"backgroundTag":"column-not-in-schema","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}