{"record":{"id":"dcb7104e6815893d","repo":"ent/ent","slug":"unexpected-fk-q-column-q","errorCode":null,"errorMessage":"unexpected fk %q column: %q","messagePattern":"unexpected fk %q column: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dialect/sql/schema/atlas.go","lineNumber":915,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\ts.AddTables(at)\n\t\tbyT[et] = at\n\t}\n\tfor _, t1 := range tables {\n\t\tif t1.View {\n\t\t\tcontinue\n\t\t}\n\t\tt2 := byT[t1]\n\t\tfor _, fk1 := range t1.ForeignKeys {\n\t\t\tfk2 := schema.NewForeignKey(fk1.Symbol).\n\t\t\t\tSetTable(t2).\n\t\t\t\tSetOnUpdate(schema.ReferenceOption(fk1.OnUpdate)).\n\t\t\t\tSetOnDelete(schema.ReferenceOption(fk1.OnDelete))\n\t\t\tfor _, c1 := range fk1.Columns {\n\t\t\t\tc2, ok := t2.Column(c1.Name)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"unexpected fk %q column: %q\", fk1.Symbol, c1.Name)\n\t\t\t\t}\n\t\t\t\tfk2.AddColumns(c2)\n\t\t\t}\n\t\t\tvar refT *schema.Table\n\t\t\tfor _, t2 := range sm[fk1.RefTable.Schema].Tables {\n\t\t\t\tif t2.Name == fk1.RefTable.Name {\n\t\t\t\t\trefT = t2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif refT == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unexpected fk %q ref-table: %q\", fk1.Symbol, fk1.RefTable.Name)\n\t\t\t}\n\t\t\tfk2.SetRefTable(refT)\n\t\t\tfor _, c1 := range fk1.RefColumns {\n\t\t\t\tc2, ok := refT.Column(c1.Name)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"unexpected fk %q ref-column: %q\", fk1.Symbol, c1.Name)","sourceCodeStart":897,"sourceCodeEnd":933,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/dialect/sql/schema/atlas.go#L897-L933","documentation":"Consistency guard while building desired-state foreign keys for the schema: for a foreign key on a table, the corresponding column could not be found on the table's desired-state representation built from the ent schema. It names the fk symbol and the missing column — meaning the schema's edge/field definitions are internally inconsistent (e.g. an edge references a column the schema no longer defines), typically a codegen or schema-definition problem.","triggerScenarios":"Thrown at dialect/sql/schema/atlas.go:915 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the named foreign key's edge definition and ensure both endpoint columns/fields exist in the ent schema","Regenerate the code (go generate) so derived table definitions are in sync with the schema","If it persists, simplify/review recently changed edges and report a reproducible schema upstream"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}