{"record":{"id":"1978ad0229ed8549","repo":"vitessio/vitess","slug":"migration-v-cannot-run-because-prior-migration-v","errorCode":null,"errorMessage":"migration %v cannot run because prior migration %v in same context has failed/was cancelled","messagePattern":"migration (.+?) cannot run because prior migration (.+?) in same context has failed/was cancelled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/onlineddl/executor.go","lineNumber":2451,"sourceCode":"\te.ownedRunningMigrations.Delete(onlineDDL.UUID)\n\treturn withError\n}\n\n// validateInOrderMigration checks whether an in-order migration should be forced to fail, either before running or\n// while running.\n// This may happen if a prior migration in the same context has failed or was cancelled.\nfunc (e *Executor) validateInOrderMigration(ctx context.Context, onlineDDL *schema.OnlineDDL) (wasFailed bool, err error) {\n\tif !onlineDDL.StrategySetting().IsInOrderCompletion() {\n\t\treturn false, nil\n\t}\n\tuuids, err := e.readFailedCancelledMigrationsInContextBeforeMigration(ctx, onlineDDL)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tif len(uuids) == 0 {\n\t\treturn false, err\n\t}\n\treturn true, e.failMigration(ctx, onlineDDL, fmt.Errorf(\"migration %v cannot run because prior migration %v in same context has failed/was cancelled\", onlineDDL.UUID, uuids[0]))\n}\n\n// analyzeDropDDLActionMigration analyzes a DROP <TABLE|VIEW> migration.\nfunc (e *Executor) analyzeDropDDLActionMigration(ctx context.Context, onlineDDL *schema.OnlineDDL) error {\n\t// Schema analysis:\n\toriginalShowCreateTable, err := e.showCreateTable(ctx, onlineDDL.Table)\n\tif err != nil {\n\t\tif sqlErr, isSQLErr := sqlerror.NewSQLErrorFromError(err).(*sqlerror.SQLError); isSQLErr {\n\t\t\tswitch sqlErr.Num {\n\t\t\tcase sqlerror.ERNoSuchTable:\n\t\t\t\t// The table does not exist. For analysis purposed, that's fine.\n\t\t\t\treturn nil\n\t\t\tdefault:\n\t\t\t\treturn vterrors.Wrapf(err, \"attempting to read definition of %v\", onlineDDL.Table)\n\t\t\t}\n\t\t}\n\t}\n\tstmt, err := e.env.Environment().Parser().ParseStrictDDL(originalShowCreateTable)","sourceCodeStart":2433,"sourceCodeEnd":2469,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/onlineddl/executor.go#L2433-L2469","documentation":"During schema analysis of a new online DDL migration, vttablet checks whether any prior migration submitted in the same context/keyspace has failed or been cancelled. If so, the new migration is immediately failed with this message to avoid building on an inconsistent schema change sequence.","triggerScenarios":"Submitting an ALTER/DROP migration in the same migration context where an earlier migration (uuids[0]) ended in status 'failed' or 'cancelled'.","commonSituations":"A batch of sequential schema changes where migration #1 failed (e.g. table locked, timeout) and subsequent migrations in the same submit request are rejected; CI pipelines replaying migration sequences after a failure.","solutions":["Find and fix the root cause of the earlier failed/cancelled migration (check its message via SHOW VITESS_MIGRATIONS)","Retry or revert the failed migration so its status no longer blocks the context","Submit the new migration in a different migration context if it is genuinely independent","Cancel/clean up stale migrations in the queue before resubmitting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before submitting a new migration, ensure no failed/cancelled migrations share the context\nrows := query(t, \"SELECT uuid FROM _vt.schema_migrations WHERE migration_context=? AND status IN ('failed','cancelled')\", ctxName)\nif len(rows) > 0 {\n    return fmt.Errorf(\"context %s blocked by failed migration %s\", ctxName, rows[0].uuid)\n}","typeGuard":null,"tryCatchPattern":"err := applySchema(ctx, ddl, migrationContext)\nif err != nil && strings.Contains(err.Error(), \"has failed/was cancelled\") {\n    // resolve the earlier failed migration, then resubmit\n}","preventionTips":["Fix or clean up failed migrations before submitting the next in a sequence","Use distinct migration contexts for independent schema changes","Monitor migration status after each batch submission","Avoid reusing a context name after a failure until resolved"],"tags":["online-ddl","migration","blocked","prior-failure"],"backgroundTag":"blocked-by-failed-migration","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}