{"record":{"id":"ce41ddb292f99581","repo":"vitessio/vitess","slug":"creating-a-table-failed-most-likely-some-tables-a","errorCode":null,"errorMessage":"creating a table failed. Most likely some tables already exist on the destination and differ from the source. Please remove all to be copied tables from the destination manually and run this command again. Full error: %v","messagePattern":"creating a table failed\\. Most likely some tables already exist on the destination and differ from the source\\. Please remove all to be copied tables from the destination manually and run this command again\\. Full error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/schema.go","lineNumber":237,"sourceCode":"\t\treturn nil\n\t}\n\n\treq := &tabletmanagerdatapb.GetSchemaRequest{Tables: tables, ExcludeTables: excludeTables, IncludeViews: includeViews}\n\tsourceSd, err := schematools.GetSchema(ctx, wr.ts, wr.tmc, sourceTabletAlias, req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"GetSchema(%v, %v, %v, %v) failed: %v\", sourceTabletAlias, tables, excludeTables, includeViews, err)\n\t}\n\n\tcreateSQLstmts := tmutils.SchemaDefinitionToSQLStrings(sourceSd)\n\n\tdestTabletInfo, err := wr.ts.GetTablet(ctx, destShardInfo.PrimaryAlias)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"GetTablet(%v) failed: %v\", destShardInfo.PrimaryAlias, err)\n\t}\n\tfor _, createSQL := range createSQLstmts {\n\t\terr = wr.applySQLShard(ctx, destTabletInfo, createSQL)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"creating a table failed.\"+\n\t\t\t\t\" Most likely some tables already exist on the destination and differ from the source.\"+\n\t\t\t\t\" Please remove all to be copied tables from the destination manually and run this command again.\"+\n\t\t\t\t\" Full error: %v\", err)\n\t\t}\n\t}\n\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 {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/schema.go#L219-L255","documentation":"CopySchemaShard applies each CREATE statement on the destination primary via applySQLShard. If any ApplySchema call fails, this error tells you the destination almost certainly already contains conflicting tables or a database with different options. MySQL skips CREATE DATABASE IF NOT EXISTS but fails CREATE TABLE for existing, differently-defined objects.","triggerScenarios":"A table or database with the same name already exists on the destination shard with a different definition (charset, columns), so the generated CREATE statement fails and the error is wrapped with this guidance message.","commonSituations":"Re-running CopySchemaShard after a partial previous run; destination shard was restored from a different backup than the source; schema drift between shards over time.","solutions":["Drop the conflicting tables/database on the destination shard, then rerun CopySchemaShard.","Inspect the wrapped 'Full error' to identify exactly which CREATE statement and table conflicted.","Run GetSchema on both tablets and diff them before rerunning."],"exampleFix":"// before\n-- destination still has old table\nCREATE TABLE `customer` (...)\n// after\nDROP TABLE `customer`;\n-- then rerun vtctldclient CopySchemaShard","handlingStrategy":"validation","validationCode":"destSd, err := schematools.GetSchema(ctx, ts, tmc, destPrimaryAlias, req)\nif err == nil && len(destSd.TableDefinitions) > 0 {\n    return fmt.Errorf(\"tables already exist on destination: %d\", len(destSd.TableDefinitions))\n}","typeGuard":null,"tryCatchPattern":"err := wr.CopySchemaShard(ctx, source, dest, tables, excludeTables, false)\nif err != nil && strings.Contains(err.Error(), \"creating a table failed\") {\n    // drop conflicting tables on destination, then retry\n}","preventionTips":["Diff source and destination schemas before copying.","Clean up partial copies before rerunning.","Keep shard schemas in sync with a schema management workflow."],"tags":["go","schema","mysql","conflict"],"backgroundTag":"table-already-exists","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}