{"record":{"id":"9d75a8664f6fb3eb","repo":"vitessio/vitess","slug":"found-no-possible-unique-key-on-s-whose-columns-9d75a8","errorCode":null,"errorMessage":"found no possible unique key on `%s` whose columns are in source table `%s`","messagePattern":"found no possible unique key on `(.+?)` whose columns are in source table `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schemadiff/onlineddl.go","lineNumber":569,"sourceCode":"\t}\n\n\ttargetUniqueKeys := PrioritizedUniqueKeys(targetCreateTableEntity)\n\tif targetUniqueKeys.Len() == 0 {\n\t\treturn nil, fmt.Errorf(\"found no possible unique key on `%s`\", targetCreateTableEntity.Name())\n\t}\n\t// VReplication supports completely different unique keys on source and target, covering\n\t// some/completely different columns. The condition is that the key on source\n\t// must use columns which all exist on target table.\n\teligibleSourceColumnsForUniqueKey := analysis.SourceSharedColumns.Union(generatedColumns(sourceColumns))\n\tanalysis.ChosenSourceUniqueKey = IterationKeysByColumns(sourceUniqueKeys, eligibleSourceColumnsForUniqueKey).First()\n\tif analysis.ChosenSourceUniqueKey == nil {\n\t\treturn nil, fmt.Errorf(\"found no possible unique key on `%s` whose columns are in target table `%s`\", sourceCreateTableEntity.Name(), targetCreateTableEntity.Name())\n\t}\n\n\teligibleTargetColumnsForUniqueKey := analysis.TargetSharedColumns.Union(generatedColumns(targetColumns))\n\tanalysis.ChosenTargetUniqueKey = IterationKeysByColumns(targetUniqueKeys, eligibleTargetColumnsForUniqueKey).First()\n\tif analysis.ChosenTargetUniqueKey == nil {\n\t\treturn nil, fmt.Errorf(\"found no possible unique key on `%s` whose columns are in source table `%s`\", targetCreateTableEntity.Name(), sourceCreateTableEntity.Name())\n\t}\n\n\tanalysis.AddedUniqueKeys = IntroducedUniqueConstraints(sourceUniqueKeys, targetUniqueKeys, alterTableAnalysis.ColumnRenameMap)\n\tanalysis.RemovedUniqueKeys = RemovedUniqueConstraints(sourceUniqueKeys, targetUniqueKeys, alterTableAnalysis.ColumnRenameMap)\n\tanalysis.RemovedForeignKeyNames, err = RemovedForeignKeyNames(sourceCreateTableEntity, targetCreateTableEntity)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tformalizeColumns := func(columnsLists ...*ColumnDefinitionEntityList) error {\n\t\tfor _, colList := range columnsLists {\n\t\t\tfor _, col := range colList.Entities {\n\t\t\t\tcol.SetExplicitDefaultAndNull()\n\t\t\t\tif err := col.SetExplicitCharsetCollate(); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\t\t}","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schemadiff/onlineddl.go#L551-L587","documentation":"Symmetric to the source-side check: the target table's unique keys are filtered to those whose columns all exist in the source table. If no target unique key qualifies, OnlineDDLMigrationTablesAnalysis fails, because VReplication must apply target-key-based operations against the source rows.","triggerScenarios":"Calling OnlineDDLMigrationTablesAnalysis when IterationKeysByColumns over the target unique keys against TargetSharedColumns ∪ generated target columns yields nil — e.g. the target's unique key covers a column added only on the target, or renamed without mapping.","commonSituations":"Target table gained a new column included in its PRIMARY/UNIQUE key while the source predates it; rename map missing the mapping so the column looks unshared; an Online DDL that altered a key to use a new column.","solutions":["Ensure the target's unique key columns exist on the source table","Add the missing/renamed column to the source before migration, or keep the key on shared columns","Provide the column rename mapping so the analyzer recognizes the shared column"],"exampleFix":"-- before (target unique key on new column 'tenant_id' absent on source)\nALTER TABLE t ADD UNIQUE KEY uk_tenant (tenant_id);\n-- after: add column to source first, then migrate\nALTER TABLE t ADD COLUMN tenant_id BIGINT, ADD UNIQUE KEY uk_tenant (tenant_id);","handlingStrategy":"validation","validationCode":"shared := analysis.TargetSharedColumns\nfor _, col := range chosenTargetUniqueKey.Columns { if !shared.Contains(col) { /* column missing on source */ } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add new key columns to both tables before migration","Avoid adding target-only columns to PRIMARY/UNIQUE keys during migration","Provide complete rename maps in ALTER statements"],"tags":["schemadiff","vreplication","unique-key","column-mismatch"],"backgroundTag":"missing-unique-key","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}