SeaQL/sea-orm · error

Owner column is not set

Error message

Owner column is not set

What it means

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.

Source

Thrown at src/entity/relation.rs:473

    /// with `AND` (`ConditionType::All`, default) or `OR` (`ConditionType::Any`).
    pub fn condition_type(mut self, condition_type: ConditionType) -> Self {
        self.condition_type = condition_type;
        self
    }
}

impl<E, R> From<RelationBuilder<E, R>> for RelationDef
where
    E: EntityTrait,
    R: EntityTrait,
{
    fn from(b: RelationBuilder<E, R>) -> Self {
        RelationDef {
            rel_type: b.rel_type,
            from_tbl: b.from_tbl,
            to_tbl: b.to_tbl,
            from_col: b.from_col.expect("Reference column is not set"),
            to_col: b.to_col.expect("Owner column is not set"),
            is_owner: b.is_owner,
            skip_fk: b.skip_fk,
            on_delete: b.on_delete,
            on_update: b.on_update,
            on_condition: b.on_condition,
            fk_name: b.fk_name,
            condition_type: b.condition_type,
        }
    }
}

macro_rules! set_foreign_key_stmt {
    ( $relation: ident, $foreign_key: ident ) => {
        let from_cols: Vec<String> = $relation
            .from_col
            .into_iter()
            .map(|col| {
                let col_name = col.to_string();

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Add the owner-side mapping: `#[sea_orm(belongs_to, from = "user_id", to = "id")]`.
  2. For builder-based definitions, call `.to_col(...)` (and `.from_col(...)`) before `into()`/`From` conversion.
  3. Regenerate the entity files with the current `sea-orm-io` CLI.

Example fix

// before
#[sea_orm(belongs_to, to = "id")]
pub user: BelongsTo<super::user::Entity>,
// after
#[sea_orm(belongs_to, from = "user_id", to = "id")]
pub user: BelongsTo<super::user::Entity>,
Defensive patterns

Strategy: validation

Validate before calling

// Startup check that every belongs_to relation maps the owner column
// #[sea_orm(belongs_to, from = "user_id", to = "id")] must include `from`
let def = <MyEntity as Related<User>>::to_relation();
debug_assert!(matches!(def.rel_type, RelationType::BelongsTo));

Type guard

fn has_owner_column(attrs: &[&str]) -> bool { attrs.iter().any(|a| a.starts_with("from = ")) }

Prevention

When it happens

Trigger: 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(...)`.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/2bdda6ab92b7f95d. Report an issue: GitHub.