SeaQL/sea-orm · error

Owner column is not set

Error message

Owner column is not set

What it means

Mirror of error 174 for the other side: converting a `RelationBuilder` to `RelationDef` panics if `to_col` (the owner column, i.e. the target table's referenced column) was never set. Both `from_col` and `to_col` must be present for a well-formed relation.

Source

Thrown at sea-orm-sync/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. Call `.to_col(...)` on the RelationBuilder before conversion.
  2. Check the relation definition includes both ends: `.from_col(fk).to_col(pk)`.
  3. Prefer statically generated relation code over runtime assembly.

Example fix

// before
let rel = Relation::BelongsTo.to(user::Entity).from_col(fk_col).into();
// after
let rel = Relation::BelongsTo.to(user::Entity).from_col(fk_col).to_col(user::Column::Id).into();
Defensive patterns

Strategy: validation

Validate before calling

// before converting: ensure both columns were supplied
let builder = Relation::BelongsTo.to(target).from_col(fk).to_col(pk); // to_col must not be omitted

Prevention

When it happens

Trigger: Building a relation dynamically and supplying only `from_col` (or only `to`), then converting to `RelationDef` — the `.expect("Owner column is not set")` fires.

Common situations: Hand-assembling foreign keys in migrations; generating relations from metadata files where the referenced column entry is absent; typos in dynamic relation definitions.

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/d7999a0c6324030b. Report an issue: GitHub.