{"record":{"id":"2bad52b8cdec39af","repo":"vitessio/vitess","slug":"copyschemashard-was-not-successful-because-the-sch","errorCode":null,"errorMessage":"CopySchemaShard was not successful because the schemas between the two tablets %v and %v differ: %v","messagePattern":"CopySchemaShard was not successful because the schemas between the two tablets (.+?) and (.+?) differ: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/schema.go","lineNumber":261,"sourceCode":"\n\t// Remember the replication position after all the above were applied.\n\tdestPrimaryPos, err := wr.tmc.PrimaryPosition(ctx, destTabletInfo.Tablet)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"CopySchemaShard: can't get replication position after schema applied: %v\", err)\n\t}\n\n\t// Although the copy was successful, we have to verify it to catch the case\n\t// where the database already existed on the destination, but with different\n\t// options e.g. a different character set.\n\t// In that case, MySQL would have skipped our CREATE DATABASE IF NOT EXISTS\n\t// statement.\n\tif !skipVerify {\n\t\tdiffs, err = schematools.CompareSchemas(ctx, wr.ts, wr.tmc, sourceTabletAlias, destShardInfo.PrimaryAlias, tables, excludeTables, includeViews)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"CopySchemaShard failed because schemas could not be compared finally: %v\", err)\n\t\t}\n\t\tif diffs != nil {\n\t\t\treturn fmt.Errorf(\"CopySchemaShard was not successful because the schemas between the two tablets %v and %v differ: %v\", sourceTabletAlias, destShardInfo.PrimaryAlias, diffs)\n\t\t}\n\t}\n\n\t// Notify Replicas to reload schema. This is best-effort.\n\treloadCtx, cancel := context.WithTimeout(ctx, waitReplicasTimeout)\n\tdefer cancel()\n\tresp, err := wr.VtctldServer().ReloadSchemaShard(reloadCtx, &vtctldatapb.ReloadSchemaShardRequest{\n\t\tKeyspace:       destKeyspace,\n\t\tShard:          destShard,\n\t\tWaitPosition:   destPrimaryPos,\n\t\tConcurrency:    10,\n\t\tIncludePrimary: true,\n\t})\n\tif resp != nil {\n\t\tfor _, e := range resp.Events {\n\t\t\tlogutil.LogEvent(wr.Logger(), e)\n\t\t}\n\t}","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/schema.go#L243-L279","documentation":"Final verification of CopySchemaShard ran successfully but found real differences (diffs) between the source and destination schemas. This usually means MySQL silently skipped statements (e.g. CREATE DATABASE IF NOT EXISTS when the DB already existed with different options like charset/collation) or some CREATEs were applied inconsistently.","triggerScenarios":"Destination database pre-existed with different charset/collation or tables differing from the source; the earlier create loop partially failed; includeViews/excludeTables choices cause differing table sets to be compared.","commonSituations":"Shard restored from an old backup; someone hand-edited schema on one shard; DB created manually with a different default character set than the source.","solutions":["Read the diffs in the error to identify mismatched objects.","Drop/recreate the differing tables or the database with the correct charset on the destination, then rerun CopySchemaShard.","Align database defaults (ALTER DATABASE ... CHARACTER SET/COLLATE) to match the source."],"exampleFix":"// before (mismatched db charset)\nCREATE DATABASE `vt_ks` CHARACTER SET latin1;\n// after\nDROP DATABASE `vt_ks`;\nCREATE DATABASE `vt_ks` CHARACTER SET utf8mb4; -- match source","handlingStrategy":"validation","validationCode":"diffs, err := schematools.CompareSchemas(ctx, ts, tmc, src, dst, tables, excl, incl)\nif err == nil && diffs != nil {\n    return fmt.Errorf(\"fix schema drift before copying: %v\", diffs)\n}","typeGuard":null,"tryCatchPattern":"err := wr.CopySchemaShard(ctx, src, dst, tables, excl, false)\nif err != nil && strings.Contains(err.Error(), \"schemas between the two tablets\") {\n    // inspect diffs, drop/recreate mismatched objects, retry\n}","preventionTips":["Keep database charsets/collations identical across shards.","Diff schemas proactively as part of reshard runbooks.","Never hand-edit schema on a single shard."],"tags":["go","schema","drift","verification"],"backgroundTag":"schema-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}