bytebase/bytebase · error

column %q

Error message

column %q

What it means

wtBuildCreateTableStmt maps storepb TableMetadata onto an ast.CreateTableStmt, building each column definition via wtBuildColumnDef. When a column definition fails to build, the error is wrapped as 'column "<name>"' so the failure identifies the offending column. The underlying error is typically a value the loader cannot map (e.g. unparseable DEFAULT/expression).

Source

Thrown at backend/plugin/schema/mysql/walk_through_loader.go:492

// wtBuildCreateTableStmt maps TableMetadata directly onto *ast.CreateTableStmt.
// Expression-bearing fields (DEFAULT, ON UPDATE, GENERATED, CHECK) go through
// wtParseExpr, which tolerates parse failures by silently dropping the
// affected feature rather than failing the whole table.
func wtBuildCreateTableStmt(tbl *storepb.TableMetadata) (*ast.CreateTableStmt, error) {
	if tbl == nil || tbl.Name == "" {
		return nil, errors.New("wtBuildCreateTableStmt: empty table")
	}
	stmt := &ast.CreateTableStmt{
		Table: &ast.TableRef{Name: tbl.Name},
	}

	for _, col := range tbl.Columns {
		if col == nil || col.Name == "" {
			continue
		}
		def, err := wtBuildColumnDef(col)
		if err != nil {
			return nil, errors.Wrapf(err, "column %q", col.Name)
		}
		stmt.Columns = append(stmt.Columns, def)
	}

	for _, idx := range tbl.Indexes {
		if idx == nil || len(idx.Expressions) == 0 {
			continue
		}
		if c := wtBuildIndexConstraint(idx); c != nil {
			stmt.Constraints = append(stmt.Constraints, c)
		}
	}

	for _, fk := range tbl.ForeignKeys {
		if fk == nil {
			continue
		}
		stmt.Constraints = append(stmt.Constraints, wtBuildFKConstraint(fk))

View on GitHub (pinned to 1870550677)

Solutions

  1. Read the wrapped cause to see which column field failed to map.
  2. Fix or normalize the column metadata (e.g. sanitize DEFAULT/ON UPDATE/GENERATED expressions) in the source metadata.
  3. Extend wtBuildColumnDef to tolerate or handle the unsupported expression instead of failing.
  4. Note the loader already tolerates expression parse failures by dropping features — check why this column bypassed that tolerance.

Example fix

// before
def, err := wtBuildColumnDef(col)
if err != nil {
    return nil, errors.Wrapf(err, "column %q", col.Name)
}
// after
def, err := wtBuildColumnDef(col)
if err != nil {
    log.Printf("dropping column %q: %v", col.Name, err)
    continue
}
Defensive patterns

Strategy: try-catch

Validate before calling

for _, col := range tbl.Columns {
    if col != nil && col.Default != nil && col.Default.Expression != "" {
        if err := checkExprParseable(col.Default.Expression); err != nil {
            return fmt.Errorf("column %q has unparseable default: %w", col.Name, err)
        }
    }
}

Try / catch

stmt, err := wtBuildCreateTableStmt(tbl)
if err != nil {
    var colErr *wrapErr
    if errors.As(err, &colErr) && strings.HasPrefix(err.Error(), "column") {
        log.Printf("table %s: %v; falling back to partial definition", tbl.Name, err)
    }
    return err
}

Prevention

When it happens

Trigger: wtInstallReal -> wtBuildCreateTableStmt on a table whose column has metadata that wtBuildColumnDef cannot convert — malformed default expressions, unsupported generation/check expressions, or invalid type metadata.

Common situations: Columns with exotic DEFAULT expressions or collations captured from a real server; metadata produced by older versions with fields the current mapper expects differently; NULL columns are skipped, so the named column exists but has problematic content.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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