{"record":{"id":"77489cec21b92b26","repo":"go-gorm/gorm","slug":"missing-field-s-for-join-table","errorCode":null,"errorMessage":"missing field %s for join table","messagePattern":"missing field (.+?) for join table","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gorm.go","lineNumber":511,"sourceCode":"\t}\n\tmodelSchema = stmt.Schema\n\n\terr = stmt.Parse(joinTable)\n\tif err != nil {\n\t\treturn err\n\t}\n\tjoinSchema = stmt.Schema\n\n\trelation, ok := modelSchema.Relationships.Relations[field]\n\tisRelation := ok && relation.JoinTable != nil\n\tif !isRelation {\n\t\treturn fmt.Errorf(\"failed to find relation: %s\", field)\n\t}\n\n\tfor _, ref := range relation.References {\n\t\tf := joinSchema.LookUpField(ref.ForeignKey.DBName)\n\t\tif f == nil {\n\t\t\treturn fmt.Errorf(\"missing field %s for join table\", ref.ForeignKey.DBName)\n\t\t}\n\n\t\tf.DataType = ref.ForeignKey.DataType\n\t\tf.GORMDataType = ref.ForeignKey.GORMDataType\n\t\tif f.Size == 0 {\n\t\t\tf.Size = ref.ForeignKey.Size\n\t\t}\n\t\tref.ForeignKey = f\n\t}\n\n\tfor name, rel := range relation.JoinTable.Relationships.Relations {\n\t\tif _, ok := joinSchema.Relationships.Relations[name]; !ok {\n\t\t\trel.Schema = joinSchema\n\t\t\tjoinSchema.Relationships.Relations[name] = rel\n\t\t}\n\t}\n\trelation.JoinTable = joinSchema\n","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/gorm.go#L493-L529","documentation":"Error \"missing field %s for join table\" thrown in go-gorm/gorm.","triggerScenarios":"Thrown at gorm.go:511 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add the missing field to the join table struct used in SetupJoinTable.","Check that the join model includes both foreign key fields with correct gorm tags.","Run AutoMigrate on the join model so its schema matches expectations."],"exampleFix":"Define the join table with all required foreign key fields: type UserRole struct { UserID uint; RoleID uint }","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"}