go-gorm/gorm · error
failed to look up field with name: %s
Error message
failed to look up field with name: %s
What it means
Error "failed to look up field with name: %s" thrown in go-gorm/gorm.
Source
Thrown at migrator/migrator.go:382
newTable = m.CurrentTable(stmt)
} else {
return err
}
}
return m.DB.Exec("ALTER TABLE ? RENAME TO ?", oldTable, newTable).Error
}
// AddColumn create `name` column for value
func (m Migrator) AddColumn(value interface{}, name string) error {
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
// avoid using the same name field
if stmt.Schema == nil {
return errors.New("failed to get schema")
}
f := stmt.Schema.LookUpField(name)
if f == nil {
return fmt.Errorf("failed to look up field with name: %s", name)
}
if !f.IgnoreMigration {
return m.DB.Exec(
"ALTER TABLE ? ADD ? ?",
m.CurrentTable(stmt), clause.Column{Name: f.DBName}, m.DB.Migrator().FullDataTypeOf(f),
).Error
}
return nil
})
}
// DropColumn drop value's `name` column
func (m Migrator) DropColumn(value interface{}, name string) error {
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
if stmt.Schema != nil {
if field := stmt.Schema.LookUpField(name); field != nil {View on GitHub (pinned to 1d6ce99528)
Solutions
- Check the field name passed to the migrator matches a struct field name, not the column name.
- Ensure the model passed to the migrator contains the field.
- Verify the schema parsed successfully before calling the migrator method.
Example fix
Ensure the column/field name passed to migrator exists on the model schema before altering it.
When it happens
Trigger: Thrown at migrator/migrator.go:382 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of go-gorm/gorm@1d6ce99528 (2026-08-15).
Data as JSON: /api/errors/c332d409c1e65cf2.
Report an issue: GitHub.