{"record":{"id":"2bdda6ab92b7f95d","repo":"SeaQL/sea-orm","slug":"owner-column-is-not-set-2bdda6","errorCode":null,"errorMessage":"Owner column is not set","messagePattern":"Owner column is not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/entity/relation.rs","lineNumber":473,"sourceCode":"    /// 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| {\n                let col_name = col.to_string();","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/entity/relation.rs#L455-L491","documentation":"In `src/entity/relation.rs:473`, the same `RelationBuilder -> RelationDef` conversion calls `.expect(\"Owner column is not set\")` on `to_col`. The relation lacks the column on the owning (source) table. As with the reference column, SeaORM cannot build the join or foreign key without it and panics at definition-conversion time.","triggerScenarios":"Declaring a relation without specifying the owner-side column — e.g. `#[sea_orm(belongs_to, to = \"id\")]` missing `from`, or a `RelationBuilder` converted via `From`/`into()` without `.to_col(...)`.","commonSituations":"Partial migration of 1.0 `Relation` enums to 2.0 attributes; hand-editing generated entities and dropping the `from = \"...\"` part; copy-pasted relation blocks with only one side of the mapping updated.","solutions":["Add the owner-side mapping: `#[sea_orm(belongs_to, from = \"user_id\", to = \"id\")]`.","For builder-based definitions, call `.to_col(...)` (and `.from_col(...)`) before `into()`/`From` conversion.","Regenerate the entity files with the current `sea-orm-io` CLI."],"exampleFix":"// before\n#[sea_orm(belongs_to, to = \"id\")]\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":"// Startup check that every belongs_to relation maps the owner column\n// #[sea_orm(belongs_to, from = \"user_id\", to = \"id\")] must include `from`\nlet def = <MyEntity as Related<User>>::to_relation();\ndebug_assert!(matches!(def.rel_type, RelationType::BelongsTo));","typeGuard":"fn has_owner_column(attrs: &[&str]) -> bool { attrs.iter().any(|a| a.starts_with(\"from = \")) }","tryCatchPattern":null,"preventionTips":["Include both `from` and `to` in every belongs_to attribute.","Lint entity files for belongs_to attributes missing `from = `.","Regenerate entities with the current sea-orm-io version 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"}