vitessio/vitess · error

creating a table failed. Most likely some tables already exi

Error message

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

What it means

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.

Source

Thrown at go/vt/wrangler/schema.go:237

		return nil
	}

	req := &tabletmanagerdatapb.GetSchemaRequest{Tables: tables, ExcludeTables: excludeTables, IncludeViews: includeViews}
	sourceSd, err := schematools.GetSchema(ctx, wr.ts, wr.tmc, sourceTabletAlias, req)
	if err != nil {
		return fmt.Errorf("GetSchema(%v, %v, %v, %v) failed: %v", sourceTabletAlias, tables, excludeTables, includeViews, err)
	}

	createSQLstmts := tmutils.SchemaDefinitionToSQLStrings(sourceSd)

	destTabletInfo, err := wr.ts.GetTablet(ctx, destShardInfo.PrimaryAlias)
	if err != nil {
		return fmt.Errorf("GetTablet(%v) failed: %v", destShardInfo.PrimaryAlias, err)
	}
	for _, createSQL := range createSQLstmts {
		err = wr.applySQLShard(ctx, destTabletInfo, createSQL)
		if err != nil {
			return fmt.Errorf("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", err)
		}
	}

	// Remember the replication position after all the above were applied.
	destPrimaryPos, err := wr.tmc.PrimaryPosition(ctx, destTabletInfo.Tablet)
	if err != nil {
		return fmt.Errorf("CopySchemaShard: can't get replication position after schema applied: %v", err)
	}

	// Although the copy was successful, we have to verify it to catch the case
	// where the database already existed on the destination, but with different
	// options e.g. a different character set.
	// In that case, MySQL would have skipped our CREATE DATABASE IF NOT EXISTS
	// statement.
	if !skipVerify {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Drop the conflicting tables/database on the destination shard, then rerun CopySchemaShard.
  2. Inspect the wrapped 'Full error' to identify exactly which CREATE statement and table conflicted.
  3. Run GetSchema on both tablets and diff them before rerunning.

Example fix

// before
-- destination still has old table
CREATE TABLE `customer` (...)
// after
DROP TABLE `customer`;
-- then rerun vtctldclient CopySchemaShard
Defensive patterns

Strategy: validation

Validate before calling

destSd, err := schematools.GetSchema(ctx, ts, tmc, destPrimaryAlias, req)
if err == nil && len(destSd.TableDefinitions) > 0 {
    return fmt.Errorf("tables already exist on destination: %d", len(destSd.TableDefinitions))
}

Try / catch

err := wr.CopySchemaShard(ctx, source, dest, tables, excludeTables, false)
if err != nil && strings.Contains(err.Error(), "creating a table failed") {
    // drop conflicting tables on destination, then retry
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/ce41ddb292f99581. Report an issue: GitHub.