beego/beego · critical

unknown field/column name `%s`

Error message

unknown field/column name `%s`

What it means

ReadValues panics while resolving the requested output columns when an expression in Values/ValuesList/ValuesFlat cannot be resolved by dbTables.parseExprs (db.go:1907). Expressions are matched against the model's fields (Go field name or mapped column via Fields.GetByAny) and walked across relations with the '__' separator; anything unresolvable aborts query building before SQL is issued.

Source

Thrown at client/orm/db.go:1909

	tables := newDbTables(mi, d.ins)

	var (
		cols  []string
		infos []*models.FieldInfo
	)

	hasExprs := len(exprs) > 0

	Q := d.ins.TableQuote()

	if hasExprs {
		cols = make([]string, 0, len(exprs))
		infos = make([]*models.FieldInfo, 0, len(exprs))
		for _, ex := range exprs {
			index, name, fi, suc := tables.parseExprs(mi, strings.Split(ex, ExprSep))
			if !suc {
				panic(fmt.Errorf("unknown field/column name `%s`", ex))
			}
			cols = append(cols, fmt.Sprintf("%s.%s%s%s %s%s%s", index, Q, fi.Column, Q, Q, name, Q))
			infos = append(infos, fi)
		}
	} else {
		cols = make([]string, 0, len(mi.Fields.DBcols))
		infos = make([]*models.FieldInfo, 0, len(exprs))
		for _, fi := range mi.Fields.FieldsDB {
			cols = append(cols, fmt.Sprintf("T0.%s%s%s %s%s%s", Q, fi.Column, Q, Q, fi.Name, Q))
			infos = append(infos, fi)
		}
	}

	query, args := d.readValuesSQL(tables, cols, qs, mi, cond, tz)

	rs, err := q.QueryContext(ctx, query, args...)
	if err != nil {
		return 0, err

View on GitHub (pinned to 939cfde380)

Solutions

  1. Use the exact Go field name (case-sensitive) or the mapped column name, joining relation hops with __ (e.g. "Profile__City__Name")
  2. Check the struct of the queried model and each hop; every intermediate segment must be a declared relation field
  3. If the target is only a physical column with no mapped field, fall back to o.Raw("SELECT ...").Values(&maps)
  4. Enable orm.Debug during development to see where resolution stopped

Example fix

// before
var maps []orm.Params
qs.Values(&maps, "Profiel__Name", "Name") // panic: unknown field/column name `Profiel__Name`

// after
var maps []orm.Params
qs.Values(&maps, "Profile__Name", "Name")
Defensive patterns

Strategy: validation

Validate before calling

func knownFirstHop(t reflect.Type, expr string) bool {
	first := strings.Split(expr, "__")[0]
	for i := 0; i < t.NumField(); i++ {
		f := t.Field(i)
		if f.Name == first || f.Tag.Get("column") == first {
			return true
		}
	}
	return false
}
if !knownFirstHop(reflect.TypeOf(User{}), exprs[0]) { /* reject before querying */ }

Try / catch

err := func() (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("bad values expr: %v", r)
		}
	}()
	_, err = qs.Values(&maps, exprs...)
	return
}()

Prevention

When it happens

Trigger: qs.Values(&maps, "Profiel__Name") with a typo in the relation name; referencing a field of another model without going through a declared relation field; wrong hop order like "Name__Profile"; using a name that is neither the Go field name nor its orm column tag.

Common situations: Renaming struct fields without grepping query strings; mixing snake_case DB names with CamelCase Go names; copy-pasting expressions from another model's queries; deep relation paths through reverse/m2m fields that parseExprs does not support.

Related errors


AI-assisted analysis of beego/beego@939cfde380 (2026-08-15). Data as JSON: /api/errors/cccca4ebb989eefc. Report an issue: GitHub.