go-pg结构和表中的不同计数字段

I use go-pg library and specify row in table "unit"

type UnitModel struct {
    Id int
    Name string

    TableName struct{} `sql:"unit"`
}

but table unit contains more then 2 fields and when i call

var unit UnitModel
err := db.Model(&unit).Where("id = ?", id).Select()

get error "pg: can't find column alter_name in model". How specify ignore other fields in table "unit"?

Read go-pg manual. There's an example, for your case is:

err := db.Model(&unit).Column("id", "name").Where("id = ?", id).Select()

In version 4.8.10 go-pg this bug fixed. If db table contain fields which not exist in structure error will not occur.