clockworklabs/SpacetimeDB · error · syn::Error
invalid combination: auto_inc, unique index or primary key c
Error message
invalid combination: auto_inc, unique index or primary key cannot have a default value
What it means
A column cannot combine `#[default(...)]` with any of `#[auto_inc]`, `#[primary_key]`, or `#[unique]`: auto-inc and primary-key values are generated by the database, and unique values must be supplied deliberately, so a client-side default would be meaningless or ambiguous. After attribute collection, the macro checks for this combination and errors at the default expression's span.
Source
Thrown at crates/bindings-macro/src/table.rs:907
check_duplicate(&auto_inc, span)?;
auto_inc = Some(span);
}
ColumnAttr::PrimaryKey(span) => {
check_duplicate(&primary_key, span)?;
primary_key = Some(span);
}
ColumnAttr::Index(index_arg) => args.indices.push(index_arg),
ColumnAttr::Default(expr, span) => {
check_duplicate(&default_value, span)?;
default_value = Some(expr);
}
}
}
if let Some(default_value) = &default_value
&& (auto_inc.is_some() || primary_key.is_some() || unique.is_some())
{
return Err(syn::Error::new(
default_value.span(),
"invalid combination: auto_inc, unique index or primary key cannot have a default value",
));
};
let column = Column {
index: col_num,
ident: field_ident,
vis: field.vis,
ty: field.ty,
default_value,
};
if unique.is_some() || primary_key.is_some() {
unique_columns.push(column.clone());
}
if auto_inc.is_some() {
sequenced_columns.push(column.clone());View on GitHub (pinned to 524b4487d9)
Solutions
- Remove `#[default(...)]` from the auto_inc / primary_key / unique column
- Or remove the conflicting attribute if the default is what you actually need
- Move the defaulting logic into the reducer that inserts the row
Example fix
// before
#[spacetimedb::table(accessor = user)]
struct User {
#[primary_key]
#[auto_inc]
#[default(0)]
id: u64,
}
// after
#[spacetimedb::table(accessor = user)]
struct User {
#[primary_key]
#[auto_inc]
id: u64,
} Defensive patterns
Strategy: validation
Validate before calling
# flag columns that combine default with auto_inc/primary_key/unique
grep -rn -A3 'default(' src/ | grep -E 'auto_inc|primary_key|unique' || echo OK Prevention
- Never combine #[default] with #[auto_inc], #[primary_key], or #[unique]
- Default optional values at the reducer call site instead of in the schema
- Review attribute stacks on id columns during code review
When it happens
Trigger: A single column carrying `#[default(expr)]` together with `#[auto_inc]`, `#[primary_key]`, or `#[unique]` (any one of them triggers the check).
Common situations: Adding `#[default(...)]` broadly to all columns during schema design; migrating older schemas where id columns happened to carry defaults.
Related errors
- unions not supported
- must specify table accessor, e.g. `#[spacetimedb::table(acce
- a direct index must be paired with a `#[unique] constraint
- not a column of the table
- spacetimedb table must be a struct
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/12382d5c21f67008.
Report an issue: GitHub.