bytebase/bytebase · error

table %s not found in schema

Error message

table %s not found in schema

What it means

classifyColumns in the MySQL backup generator resolves a table's schema metadata from the previously synced catalog metadata. It looks up the table by name (case-insensitively or exactly depending on case-sensitivity settings) in the default schema of the database metadata; if the lookup returns nil it cannot split columns into generated vs normal columns and throws this error. It indicates the queried table does not exist in Bytebase's cached schema metadata for that database.

Source

Thrown at backend/plugin/parser/mysql/backup.go:689

	schema := dbMetadata.GetSchemaMetadata("")
	if schema == nil {
		return nil, nil, errors.New("failed to get schema metadata")
	}

	var tableSchema *model.TableMetadata
	if !isCaseSensitive {
		for _, tableName := range schema.ListTableNames() {
			if strings.EqualFold(tableName, table.Table) {
				tableSchema = schema.GetTable(tableName)
				break
			}
		}
	} else {
		tableSchema = schema.GetTable(table.Table)
	}
	if tableSchema == nil {
		return nil, nil, errors.Errorf("table %s not found in schema", table.Table)
	}

	var generatedColumns, normalColumns []string
	for _, column := range tableSchema.GetProto().GetColumns() {
		if column.GetGeneration() != nil {
			generatedColumns = append(generatedColumns, column.GetName())
		} else {
			normalColumns = append(normalColumns, column.GetName())
		}
	}

	return generatedColumns, normalColumns, nil
}

View on GitHub (pinned to 1870550677)

Solutions

  1. Verify the table name in the backup configuration matches an existing table (check case exactly on case-sensitive instances).
  2. Re-sync the instance/database schema metadata in Bytebase so the catalog contains the table.
  3. Confirm the backup task targets the correct database — the lookup only searches that database's default schema.
  4. If the table was recently created, wait for/trigger a metadata sync before running the backup.

Example fix

// before: metadata never synced, table missing from catalog
// after: ensure sync before classifying
if err := syncDatabaseMetadata(ctx, instanceID, table.Database); err != nil {
	return nil, nil, err
}
tableSchema = schema.GetTable(table.Table)
Defensive patterns

Strategy: validation

Validate before calling

schema := dbMetadata.GetSchemaMetadata("")
if schema == nil {
	return errors.New("schema metadata unavailable; sync the database first")
}
found := false
for _, name := range schema.ListTableNames() {
	if strings.EqualFold(name, table.Table) { found = true; break }
}
if !found {
	return fmt.Errorf("table %q not present in metadata; re-sync before backup", table.Table)
}

Type guard

func tableInSchema(schema *model.SchemaMetadata, name string) bool {
	if schema == nil { return false }
	for _, t := range schema.ListTableNames() {
		if strings.EqualFold(t, name) { return true }
	}
	return false
}

Try / catch

if _, _, err := classifyColumns(ctx, instanceID, table, meta); err != nil {
	if strings.Contains(err.Error(), "not found in schema") {
		// mark backup task as failed-needs-sync and trigger metadata sync
		return reconcileMetadataAndRetry(ctx, instanceID, table.Database)
	}
	return err
}

Prevention

When it happens

Trigger: generateSQLForTable/doGenerate are called with a TableMetadata{name, database} whose table name is absent from the database's schema metadata — the database exists but the table name in the backup config does not match any table in the synced metadata (case-sensitive mode requires exact match).

Common situations: Table was dropped after backup task creation; stale/incomplete schema catalog because the instance metadata hasn't been synced since the table was created; case mismatch between config and actual table name on a case-sensitive setup; typo in table name; referencing a table from the wrong database.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/19e8125ac8c39ea5. Report an issue: GitHub.