{"record":{"id":"4db260ca8d95ec32","repo":"bytebase/bytebase","slug":"column-q","errorCode":null,"errorMessage":"column %q","messagePattern":"column %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/schema/mysql/walk_through_loader.go","lineNumber":492,"sourceCode":"// wtBuildCreateTableStmt maps TableMetadata directly onto *ast.CreateTableStmt.\n// Expression-bearing fields (DEFAULT, ON UPDATE, GENERATED, CHECK) go through\n// wtParseExpr, which tolerates parse failures by silently dropping the\n// affected feature rather than failing the whole table.\nfunc wtBuildCreateTableStmt(tbl *storepb.TableMetadata) (*ast.CreateTableStmt, error) {\n\tif tbl == nil || tbl.Name == \"\" {\n\t\treturn nil, errors.New(\"wtBuildCreateTableStmt: empty table\")\n\t}\n\tstmt := &ast.CreateTableStmt{\n\t\tTable: &ast.TableRef{Name: tbl.Name},\n\t}\n\n\tfor _, col := range tbl.Columns {\n\t\tif col == nil || col.Name == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tdef, err := wtBuildColumnDef(col)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"column %q\", col.Name)\n\t\t}\n\t\tstmt.Columns = append(stmt.Columns, def)\n\t}\n\n\tfor _, idx := range tbl.Indexes {\n\t\tif idx == nil || len(idx.Expressions) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tif c := wtBuildIndexConstraint(idx); c != nil {\n\t\t\tstmt.Constraints = append(stmt.Constraints, c)\n\t\t}\n\t}\n\n\tfor _, fk := range tbl.ForeignKeys {\n\t\tif fk == nil {\n\t\t\tcontinue\n\t\t}\n\t\tstmt.Constraints = append(stmt.Constraints, wtBuildFKConstraint(fk))","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/schema/mysql/walk_through_loader.go#L474-L510","documentation":"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).","triggerScenarios":"wtInstallReal -> wtBuildCreateTableStmt on a table whose column has metadata that wtBuildColumnDef cannot convert — malformed default expressions, unsupported generation/check expressions, or invalid type metadata.","commonSituations":"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.","solutions":["Read the wrapped cause to see which column field failed to map.","Fix or normalize the column metadata (e.g. sanitize DEFAULT/ON UPDATE/GENERATED expressions) in the source metadata.","Extend wtBuildColumnDef to tolerate or handle the unsupported expression instead of failing.","Note the loader already tolerates expression parse failures by dropping features — check why this column bypassed that tolerance."],"exampleFix":"// before\ndef, err := wtBuildColumnDef(col)\nif err != nil {\n    return nil, errors.Wrapf(err, \"column %q\", col.Name)\n}\n// after\ndef, err := wtBuildColumnDef(col)\nif err != nil {\n    log.Printf(\"dropping column %q: %v\", col.Name, err)\n    continue\n}","handlingStrategy":"try-catch","validationCode":"for _, col := range tbl.Columns {\n    if col != nil && col.Default != nil && col.Default.Expression != \"\" {\n        if err := checkExprParseable(col.Default.Expression); err != nil {\n            return fmt.Errorf(\"column %q has unparseable default: %w\", col.Name, err)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"stmt, err := wtBuildCreateTableStmt(tbl)\nif err != nil {\n    var colErr *wrapErr\n    if errors.As(err, &colErr) && strings.HasPrefix(err.Error(), \"column\") {\n        log.Printf(\"table %s: %v; falling back to partial definition\", tbl.Name, err)\n    }\n    return err\n}","preventionTips":["Sanitize DEFAULT/ON UPDATE/GENERATED expressions when capturing column metadata","Extend wtBuildColumnDef tolerance for unsupported expressions instead of propagating failures","Round-trip test real-world column definitions (exotic defaults, generated columns) through the loader"],"tags":["mysql","column","metadata","loader"],"backgroundTag":"schema-validation-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}