{"record":{"id":"67bbcffa29695a9a","repo":"SeaQL/sea-orm","slug":"reference-column-is-not-set","errorCode":null,"errorMessage":"Reference column is not set","messagePattern":"Reference column is not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/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/sea-orm-sync/src/entity/relation.rs#L454-L490","documentation":"Converting a `RelationBuilder` into a `RelationDef` requires the `from_col` (reference column) to have been set via `from_col()`/`from()`. If the builder never received it, the `From` impl panics with 'Reference column is not set'. Relations fundamentally need both sides' columns to generate joins and foreign keys.","triggerScenarios":"Programmatically constructing a relation with `Relation::new()`/`has_many(...)` style builders and forgetting the `.from_col(...)` call before converting to `RelationDef` (e.g. in custom schema/migration code or dynamic relation construction).","commonSituations":"Writing custom migrations or schema helpers that assemble relations at runtime; dynamic query builders assembling joins from config where a column key is missing.","solutions":["Call `.from_col(ColumnRef/Identity)` on the builder before converting it into a RelationDef.","Validate relation config data before building: ensure both reference and owner columns exist.","Use generated entity relations (`Entity::has_many(...)` macros) which always populate both columns."],"exampleFix":"// before\nlet rel = Relation::HasMany.to(R::default()).into();\n// after\nlet rel = Relation::HasMany.to(R::default()).from_col(user::Column::Id).into();","handlingStrategy":"validation","validationCode":"// before converting a builder to RelationDef\nlet def = Relation::HasMany.to(target)\n    .from_col(src_col) // must be set\n    .to_col(target_col);\nassert!(matches!(def, _)); // compile-time builder chaining guarantees both columns","typeGuard":"fn relation_complete(b: &RelationBuilder<impl EntityTrait, impl Related<impl EntityTrait>>) -> bool { true } // prefer typed builder chain so missing cols cannot compile","tryCatchPattern":null,"preventionTips":["Always chain .from_col(...) when constructing relations manually.","Use generated entity relation helpers instead of runtime Relation building.","Validate relation metadata (both column ends present) before building."],"tags":["panic","relation","builder","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"}