{"record":{"id":"d86a6eac469d5a25","repo":"vitessio/vitess","slug":"column-v-not-found-in-table-v-on-tablet-v","errorCode":null,"errorMessage":"column %v not found in table %v on tablet %v","messagePattern":"column (.+?) not found in table (.+?) on tablet (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vdiff/table_plan.go","lineNumber":150,"sourceCode":"\t\t}\n\t}\n\tfields := make(map[string]querypb.Type)\n\tfor _, field := range tp.table.Fields {\n\t\tfields[strings.ToLower(field.Name)] = field.Type\n\t}\n\n\ttargetSelect.SetSelectExprs(td.adjustForSourceTimeZone(targetSelect.GetColumns(), fields)...)\n\t// Start with adding all columns for comparison.\n\ttp.compareCols = make([]compareColInfo, sourceSelect.GetColumnCount())\n\tfor i := range tp.compareCols {\n\t\ttp.compareCols[i].colIndex = i\n\t\tcolname, err := getColumnNameForSelectExpr(targetSelect.GetColumns()[i])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\t_, ok := fields[colname]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"column %v not found in table %v on tablet %v\",\n\t\t\t\tcolname, tp.table.Name, td.wd.ct.vde.thisTablet.Alias)\n\t\t}\n\t\ttp.compareCols[i].colName = colname\n\t}\n\n\tsourceSelect.From = sel.From\n\t// The target table name should the one that matched the rule.\n\t// It can be different from the source table.\n\ttargetSelect.From = sqlparser.TableExprs{\n\t\t&sqlparser.AliasedTableExpr{\n\t\t\tExpr: &sqlparser.TableName{\n\t\t\t\tName: sqlparser.NewIdentifierCS(tp.table.Name),\n\t\t\t},\n\t\t},\n\t}\n\n\tif len(tp.table.PrimaryKeyColumns) == 0 {\n\t\t// We use the columns from a PKE if there is one.","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vdiff/table_plan.go#L132-L168","documentation":"After building the target select list, vdiff validates that every derived column name exists in the target table's schema (fields fetched from this tablet). If a computed/aliased column name is missing from the target table, it throws `column %v not found in table %v on tablet %v`.","triggerScenarios":"A select expression's alias (or column) does not correspond to any actual column of the target table on the local tablet — e.g. rule selects `select a as x, b` but the target table has no column `x`; or schema drift between source and target.","commonSituations":"MoveTables between tables with differing schemas; adding/renaming columns mid-migration so vreplication rules reference old names; hand-edited rules with aliases that don't exist on the target; resharding where the target table schema lags.","solutions":["Compare source and target schemas (`SHOW CREATE TABLE` on both) and align them (apply the ALTER on the lagging side)","Fix the workflow's filter rule so every selected/aliased column exists on the target table","Re-run the vdiff after schemas converge; if using --tables, restrict the diff to tables whose schemas match","Verify the tablet being used for the diff has the latest schema (run with a primary tablet that has reloaded its schema)"],"exampleFix":"// before (rule alias has no target column)\nselect price * qty as total from orders\n// after (add column on target or select existing columns)\nalter table orders add column total int; -- then select ... as total","handlingStrategy":"validation","validationCode":"// before vdiff, check every rule column/alias exists on the target table\ntargetCols := map[string]bool{} // from SHOW CREATE TABLE / information_schema on target\nfor _, col := range ruleSelectColsAndAliases {\n  if !targetCols[strings.ToLower(col)] {\n    return fmt.Errorf(\"column %s missing on target table\", col)\n  }\n}","typeGuard":"func columnsExist(cols []string, tableSchema map[string]bool) bool {\n  for _, c := range cols {\n    if !tableSchema[strings.ToLower(c)] { return false }\n  }\n  return true\n}","tryCatchPattern":"tp, err := buildTablePlan(...)\nif err != nil {\n  if strings.Contains(err.Error(), \"not found in table\") {\n    return fmt.Errorf(\"schema drift detected: %w; align source/target schemas\", err)\n  }\n  return err\n}","preventionTips":["Keep source and target schemas in sync during MoveTables","Apply DDL to both sides before continuing the workflow","Don't edit rules to reference columns absent on the target","Reload tablet schema after DDL before running vdiff"],"tags":["vdiff","schema","schema-drift"],"backgroundTag":"column-not-found-in-table","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}