{"record":{"id":"588837d02c8f0139","repo":"jmoiron/sqlx","slug":"missing-destination-name-s-in-t","errorCode":null,"errorMessage":"missing destination name %s in %T","messagePattern":"missing destination name (.+?) in %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sqlx.go","lineNumber":621,"sourceCode":"\tv := reflect.ValueOf(dest)\n\n\tif v.Kind() != reflect.Ptr {\n\t\treturn errors.New(\"must pass a pointer, not a value, to StructScan destination\")\n\t}\n\n\tv = v.Elem()\n\n\tif !r.started {\n\t\tcolumns, err := r.Columns()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tm := r.Mapper\n\n\t\tr.fields = m.TraversalsByName(v.Type(), columns)\n\t\t// if we are not unsafe and are missing fields, return an error\n\t\tif f, err := missingFields(r.fields); err != nil && !r.unsafe {\n\t\t\treturn fmt.Errorf(\"missing destination name %s in %T\", columns[f], dest)\n\t\t}\n\t\tr.values = make([]interface{}, len(columns))\n\t\tr.started = true\n\t}\n\n\terr := fieldsByTraversal(v, r.fields, r.values, true)\n\tif err != nil {\n\t\treturn err\n\t}\n\t// scan into the struct field pointers and append to our results\n\terr = r.Scan(r.values...)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn r.Err()\n}\n\n// Connect to a database and verify with a ping.","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/jmoiron/sqlx/blob/41dac167fdad5e3fd81d66cafba0951dc6823a30/sqlx.go#L603-L639","documentation":"During Rows.StructScan, sqlx maps result-set column names to fields of the destination struct via the reflectx mapper. If a returned column has no matching (tagged or name-matching) exported struct field and the mapper is not in unsafe mode, the scan is aborted with this error. It is a contract check that every selected column has somewhere to go in the struct.","triggerScenarios":"Calling rows.StructScan(dest) (via the internal Fields scanner) where m.TraversalsByName finds no struct field for at least one column in the current result set, while r.unsafe is false (default).","commonSituations":"Adding a column to a SELECT without updating the struct; using DB column names that don't match struct fields and forgetting `db:\"column_name\"` tags; SELECT * on a table whose schema changed; struct fields being unexported so the mapper can't see them.","solutions":["Add or fix `db:\"column_name\"` tags on the struct fields for the unmatched columns.","Rename either the struct field or the SQL column alias (e.g. SELECT user_id AS id) so names match.","Run the query with db.Unsafe() so unmapped columns are silently ignored.","Drop the extra column from the SELECT list or select explicit columns instead of *."],"exampleFix":"// before\ntype User struct {\n    Name string `db:\"name\"`\n}\ndb.Select(&users, \"SELECT id, name FROM users\")\n\n// after\ntype User struct {\n    ID   int    `db:\"id\"`\n    Name string `db:\"name\"`\n}\ndb.Select(&users, \"SELECT id, name FROM users\")","handlingStrategy":"validation","validationCode":"cols, _ := rows.Columns()\nfor _, c := range cols {\n    if _, ok := structFieldFor(c, reflect.TypeOf(dest)); !ok {\n        return fmt.Errorf(\"column %q has no matching struct field\", c)\n    }\n}","typeGuard":"func isStructPtr(dest interface{}) bool {\n    t := reflect.TypeOf(dest)\n    return t != nil && t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct\n}","tryCatchPattern":null,"preventionTips":["Always tag struct fields with db:\"column_name\" explicitly.","Run a startup test that scans every query against its destination struct.","Select explicit columns instead of SELECT *.","Keep struct definitions in sync with schema migrations."],"tags":["sqlx","struct-scan","column-mapping","reflection"],"backgroundTag":"missing-destination-column-mapping","analyzedSha":"41dac167fdad5e3fd81d66cafba0951dc6823a30","analyzedAt":"2026-09-03T06:10:20.382Z","contentChangedAt":"2026-09-03T06:10:20.382Z","schemaVersion":2},"datasetVersion":"2026-09-10T12:17:11.382Z"}