{"record":{"id":"c332d409c1e65cf2","repo":"go-gorm/gorm","slug":"failed-to-look-up-field-with-name-s","errorCode":null,"errorMessage":"failed to look up field with name: %s","messagePattern":"failed to look up field with name: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"migrator/migrator.go","lineNumber":382,"sourceCode":"\t\t\tnewTable = m.CurrentTable(stmt)\n\t\t} else {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn m.DB.Exec(\"ALTER TABLE ? RENAME TO ?\", oldTable, newTable).Error\n}\n\n// AddColumn create `name` column for value\nfunc (m Migrator) AddColumn(value interface{}, name string) error {\n\treturn m.RunWithValue(value, func(stmt *gorm.Statement) error {\n\t\t// avoid using the same name field\n\t\tif stmt.Schema == nil {\n\t\t\treturn errors.New(\"failed to get schema\")\n\t\t}\n\t\tf := stmt.Schema.LookUpField(name)\n\t\tif f == nil {\n\t\t\treturn fmt.Errorf(\"failed to look up field with name: %s\", name)\n\t\t}\n\n\t\tif !f.IgnoreMigration {\n\t\t\treturn m.DB.Exec(\n\t\t\t\t\"ALTER TABLE ? ADD ? ?\",\n\t\t\t\tm.CurrentTable(stmt), clause.Column{Name: f.DBName}, m.DB.Migrator().FullDataTypeOf(f),\n\t\t\t).Error\n\t\t}\n\n\t\treturn nil\n\t})\n}\n\n// DropColumn drop value's `name` column\nfunc (m Migrator) DropColumn(value interface{}, name string) error {\n\treturn m.RunWithValue(value, func(stmt *gorm.Statement) error {\n\t\tif stmt.Schema != nil {\n\t\t\tif field := stmt.Schema.LookUpField(name); field != nil {","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/migrator/migrator.go#L364-L400","documentation":"Error \"failed to look up field with name: %s\" thrown in go-gorm/gorm.","triggerScenarios":"Thrown at migrator/migrator.go:382 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":"Ensure the column/field name passed to migrator exists on the model schema before altering it.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d6ce99528060be18a42be09aca8d39efcb47f28","analyzedAt":"2026-08-15T13:01:23.433Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}