{"record":{"id":"2bf26fe6f962c21c","repo":"vitessio/vitess","slug":"source-and-target-columns-must-be-of-same-length","errorCode":null,"errorMessage":"source and target columns must be of same length","messagePattern":"source and target columns must be of same length","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schemadiff/onlineddl.go","lineNumber":311,"sourceCode":"}\n\n// GetExpandedColumnNames is given source and target shared columns, and returns the list of columns whose data type is expanded.\n// An expanded data type is one where the target can have a value which the source does not. Examples:\n// - any NOT NULL to NULLable (a NULL in the target cannot appear on source)\n// - INT -> BIGINT (obvious)\n// - BIGINT UNSIGNED -> INT SIGNED (negative values)\n// - TIMESTAMP -> TIMESTAMP(3)\n// etc.\nfunc GetExpandedColumns(\n\tsourceColumns *ColumnDefinitionEntityList,\n\ttargetColumns *ColumnDefinitionEntityList,\n) (\n\texpandedColumns *ColumnDefinitionEntityList,\n\texpandedDescriptions map[string]string,\n\terr error,\n) {\n\tif len(sourceColumns.Entities) != len(targetColumns.Entities) {\n\t\treturn nil, nil, errors.New(\"source and target columns must be of same length\")\n\t}\n\n\texpandedEntities := []*ColumnDefinitionEntity{}\n\texpandedDescriptions = map[string]string{}\n\tfor i := range sourceColumns.Entities {\n\t\t// source and target columns assumed to be mapped 1:1, same length\n\t\tsourceColumn := sourceColumns.Entities[i]\n\t\ttargetColumn := targetColumns.Entities[i]\n\n\t\tif isExpanded, description := ColumnChangeExpandsDataRange(sourceColumn, targetColumn); isExpanded {\n\t\t\texpandedEntities = append(expandedEntities, sourceColumn)\n\t\t\texpandedDescriptions[sourceColumn.Name()] = description\n\t\t}\n\t}\n\treturn NewColumnDefinitionEntityList(expandedEntities), expandedDescriptions, nil\n}\n\n// AnalyzeSharedColumns returns the intersection of two lists of columns in same order as the first list","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schemadiff/onlineddl.go#L293-L329","documentation":"GetExpandedColumns expands paired column definitions (e.g. expanding per-column attributes) and requires the source and target column lists to map 1:1. It returns this error when the number of entities in sourceColumns differs from targetColumns, since pairwise expansion would be undefined.","triggerScenarios":"OnlineDDLMigrationTablesAnalysis calling GetExpandedColumns with source and target table schemas that have a different column count (columns added or dropped between source and target).","commonSituations":"Analyzing an ALTER TABLE migration that ADD/DROP COLUMNs; drift between the actual table schema and the migration's target schema definition.","solutions":["Ensure the analyzed ALTER does not change the number of columns, or split it into column-count-preserving steps","Verify the source and target table definitions used for the analysis are current","Re-run the migration analysis after aligning the two schema versions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"src := countColumns(sourceSchema)\ntgt := countColumns(targetSchema)\nif src != tgt { return fmt.Errorf(\"column count changed (%d -> %d); split the migration\", src, tgt) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Split ADD/DROP COLUMN migrations from attribute-only changes","Refresh table analyses after schema changes","Verify 1:1 column mapping before column-pair analysis"],"tags":["onlineddl","columns","schema-analysis"],"backgroundTag":"schema-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}