{"record":{"id":"ebe289545c700900","repo":"vitessio/vitess","slug":"schemas-are-different-s-v-differs-from-s","errorCode":null,"errorMessage":"schemas are different:\n%s: %v\n differs from:\n%s: %v","messagePattern":"schemas are different:\n(.+?): (.+?)\n differs from:\n(.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/tmutils/schema.go","lineNumber":225,"sourceCode":"\t\t\tsqlStrings = append(sqlStrings, strings.Join(lines, \"\\n\"))\n\t\t}\n\t}\n\n\treturn append(sqlStrings, createViewSQL...)\n}\n\n// DiffSchema generates a report on what's different between two SchemaDefinitions\n// including views, but Vitess internal tables are ignored.\nfunc DiffSchema(leftName string, left *tabletmanagerdatapb.SchemaDefinition, rightName string, right *tabletmanagerdatapb.SchemaDefinition, er concurrency.ErrorRecorder) {\n\tif left == nil && right == nil {\n\t\treturn\n\t}\n\tif left == nil || right == nil {\n\t\ter.RecordError(fmt.Errorf(\"schemas are different:\\n%s: %v, %s: %v\", leftName, left, rightName, right))\n\t\treturn\n\t}\n\tif left.DatabaseSchema != right.DatabaseSchema {\n\t\ter.RecordError(fmt.Errorf(\"schemas are different:\\n%s: %v\\n differs from:\\n%s: %v\", leftName, left.DatabaseSchema, rightName, right.DatabaseSchema))\n\t}\n\n\tleftIndex := 0\n\trightIndex := 0\n\tfor leftIndex < len(left.TableDefinitions) && rightIndex < len(right.TableDefinitions) {\n\t\t// extra table on the left side\n\t\tif left.TableDefinitions[leftIndex].Name < right.TableDefinitions[rightIndex].Name {\n\t\t\tif !schema.IsInternalOperationTableName(left.TableDefinitions[leftIndex].Name) {\n\t\t\t\ter.RecordError(fmt.Errorf(\"%v has an extra table named %v\", leftName, left.TableDefinitions[leftIndex].Name))\n\t\t\t}\n\t\t\tleftIndex++\n\t\t\tcontinue\n\t\t}\n\n\t\t// extra table on the right side\n\t\tif left.TableDefinitions[leftIndex].Name > right.TableDefinitions[rightIndex].Name {\n\t\t\tif !schema.IsInternalOperationTableName(right.TableDefinitions[rightIndex].Name) {\n\t\t\t\ter.RecordError(fmt.Errorf(\"%v has an extra table named %v\", rightName, right.TableDefinitions[rightIndex].Name))","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/tmutils/schema.go#L207-L243","documentation":"DiffSchema records this error when both SchemaDefinitions are non-nil but their DatabaseSchema strings (the CREATE DATABASE / default character set portion) differ. It shows the left and right database-level schema side by side.","triggerScenarios":"DiffSchema invoked on two tablets whose underlying MySQL databases were created with different definitions — e.g. different CREATE DATABASE charset/collation statements.","commonSituations":"Tablets provisioned at different times with different default charset (utf8 vs utf8mb4); manual ALTER DATABASE on one replica; primary migrated to a new cluster with a different database definition.","solutions":["Run the desired ALTER DATABASE statement on the mismatching tablet's MySQL so both database definitions match","Re-create the database consistently and re-copy the schema","Update provisioning tooling to use a single canonical CREATE DATABASE statement"],"exampleFix":"// before\n-- tablet A: CREATE DATABASE vt_app CHARACTER SET utf8\n-- tablet B: CREATE DATABASE vt_app CHARACTER SET utf8mb4\n// after (on tablet B's MySQL)\nALTER DATABASE vt_app CHARACTER SET utf8;","handlingStrategy":"validation","validationCode":"leftDb, rightDb := left.GetDatabaseSchema(), right.GetDatabaseSchema()\nif leftDb != rightDb {\n    log.Warn(\"database schema mismatch before diff\", slog.String(\"left\", leftDb), slog.String(\"right\", rightDb))\n}","typeGuard":null,"tryCatchPattern":"er := concurrency.AllErrorRecorder{}\ntmutils.DiffSchema(\"left\", left, \"right\", right, &er)\nif er.HasErrors() {\n    for _, e := range er.Errors { log.Warn(\"schema diff\", slog.Any(\"error\", e)) }\n    return er.Error()\n}","preventionTips":["Provision all MySQL instances with the same CREATE DATABASE charset/collation template","Avoid manual ALTER DATABASE on replicas","Pin the database definition in provisioning/IaC tooling","Include database-level schema in periodic consistency checks"],"tags":["schema","consistency-check","mysql","vitess"],"backgroundTag":"schema-drift-between-tablets","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}