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
- Call `.to_col(...)` on the RelationBuilder before conversion.
- Check the relation definition includes both ends: `.from_col(fk).to_col(pk)`.
- 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
- Always supply .to_col(...) alongside .from_col(...) for belongs_to relations.
- Check migration/metadata inputs for the referenced (owner) column before building relations.
- Prefer code-generated relations over dynamic assembly.
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
- Reference column is not set
- index out of bounds: the ActiveHasMany is NotSet (index: {in
- called `BelongsTo::unwrap()` on an `Unloaded` value
- called `BelongsTo::unwrap()` on a `Loaded(None)` value
- index out of bounds: the HasMany is Unloaded (index: {index}
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/d7999a0c6324030b.
Report an issue: GitHub.