{"record":{"id":"358d0f155f36a735","repo":"SeaQL/sea-orm","slug":"reference-column-is-not-set-358d0f","errorCode":null,"errorMessage":"Reference column is not set","messagePattern":"Reference column is not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/entity/relation.rs","lineNumber":472,"sourceCode":"    /// Combine the column equality and [`on_condition`](Self::on_condition)\n    /// with `AND` (`ConditionType::All`, default) or `OR` (`ConditionType::Any`).\n    pub fn condition_type(mut self, condition_type: ConditionType) -> Self {\n        self.condition_type = condition_type;\n        self\n    }\n}\n\nimpl<E, R> From<RelationBuilder<E, R>> for RelationDef\nwhere\n    E: EntityTrait,\n    R: EntityTrait,\n{\n    fn from(b: RelationBuilder<E, R>) -> Self {\n        RelationDef {\n            rel_type: b.rel_type,\n            from_tbl: b.from_tbl,\n            to_tbl: b.to_tbl,\n            from_col: b.from_col.expect(\"Reference column is not set\"),\n            to_col: b.to_col.expect(\"Owner column is not set\"),\n            is_owner: b.is_owner,\n            skip_fk: b.skip_fk,\n            on_delete: b.on_delete,\n            on_update: b.on_update,\n            on_condition: b.on_condition,\n            fk_name: b.fk_name,\n            condition_type: b.condition_type,\n        }\n    }\n}\n\nmacro_rules! set_foreign_key_stmt {\n    ( $relation: ident, $foreign_key: ident ) => {\n        let from_cols: Vec<String> = $relation\n            .from_col\n            .into_iter()\n            .map(|col| {","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/entity/relation.rs#L454-L490","documentation":"In `src/entity/relation.rs:472`, converting a `RelationBuilder` into a public `RelationDef` calls `.expect(\"Reference column is not set\")` on `from_col`. The relation was constructed without ever specifying the column on the referenced (target) table. SeaORM needs both ends of a relation to build joins and foreign keys, so an unset reference column is a definition error surfaced as a panic.","triggerScenarios":"Defining a `belongs_to` / `has_many` relation in an entity without the required `#[sea_orm(belongs_to, from = \"...\", to = \"...\")]` column mapping (or the 1.0-style `.from_col(...)`/`.to_col(...)` builder calls), then using that relation (join, load, link).","commonSituations":"Migrating from SeaORM 1.0 relation enums to the 2.0 `#[sea_orm::model]` attributes and forgetting the `from`/`to` mapping; typos in relation attribute keys; relations declared for views/aliased tables without explicit columns.","solutions":["Add the missing column mapping: `#[sea_orm(belongs_to, from = \"user_id\", to = \"id\")]` on the relation field.","For builder-based definitions, chain `.from_col(...)` and `.to_col(...)` before converting to `RelationDef`.","Regenerate entities with `sea-orm-io generate entity` so relations are fully specified."],"exampleFix":"// before\n#[sea_orm(belongs_to)]\npub user: BelongsTo<super::user::Entity>,\n// after\n#[sea_orm(belongs_to, from = \"user_id\", to = \"id\")]\npub user: BelongsTo<super::user::Entity>,\n","handlingStrategy":"validation","validationCode":"// Compile-time: ensure the relation attribute carries from/to\n// Runtime smoke test at startup:\nlet def = RelationDef::from(<MyEntity as Related<OtherEntity>>::to_relation());\nassert!(!format!(\"{:?}\", def.from_col).contains(\"None\"));","typeGuard":"fn relation_fully_specified<E: EntityTrait, R: EntityTrait>(r: &RelationDef) -> bool {\n    !matches!(r.from_tbl, TableRef::default()) // and from_col/to_col set by successful From conversion\n}","tryCatchPattern":null,"preventionTips":["Use the 2.0 attribute form with explicit from/to: #[sea_orm(belongs_to, from = \"fk\", to = \"id\")].","Never hand-convert RelationBuilder to RelationDef without setting both columns.","Regenerate entities after schema changes."],"tags":["relation","entity-definition","missing-column"],"backgroundTag":"missing-required-argument","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}