{"record":{"id":"12382d5c21f67008","repo":"clockworklabs/SpacetimeDB","slug":"invalid-combination-auto-inc-unique-index-or-pri","errorCode":null,"errorMessage":"invalid combination: auto_inc, unique index or primary key cannot have a default value","messagePattern":"invalid combination: auto_inc, unique index or primary key cannot have a default value","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bindings-macro/src/table.rs","lineNumber":907,"sourceCode":"                    check_duplicate(&auto_inc, span)?;\n                    auto_inc = Some(span);\n                }\n                ColumnAttr::PrimaryKey(span) => {\n                    check_duplicate(&primary_key, span)?;\n                    primary_key = Some(span);\n                }\n                ColumnAttr::Index(index_arg) => args.indices.push(index_arg),\n                ColumnAttr::Default(expr, span) => {\n                    check_duplicate(&default_value, span)?;\n                    default_value = Some(expr);\n                }\n            }\n        }\n\n        if let Some(default_value) = &default_value\n            && (auto_inc.is_some() || primary_key.is_some() || unique.is_some())\n        {\n            return Err(syn::Error::new(\n                default_value.span(),\n                \"invalid combination: auto_inc, unique index or primary key cannot have a default value\",\n            ));\n        };\n\n        let column = Column {\n            index: col_num,\n            ident: field_ident,\n            vis: field.vis,\n            ty: field.ty,\n            default_value,\n        };\n\n        if unique.is_some() || primary_key.is_some() {\n            unique_columns.push(column.clone());\n        }\n        if auto_inc.is_some() {\n            sequenced_columns.push(column.clone());","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-macro/src/table.rs#L889-L925","documentation":"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.","triggerScenarios":"A single column carrying `#[default(expr)]` together with `#[auto_inc]`, `#[primary_key]`, or `#[unique]` (any one of them triggers the check).","commonSituations":"Adding `#[default(...)]` broadly to all columns during schema design; migrating older schemas where id columns happened to carry defaults.","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"],"exampleFix":"// before\n#[spacetimedb::table(accessor = user)]\nstruct User {\n    #[primary_key]\n    #[auto_inc]\n    #[default(0)]\n    id: u64,\n}\n\n// after\n#[spacetimedb::table(accessor = user)]\nstruct User {\n    #[primary_key]\n    #[auto_inc]\n    id: u64,\n}","handlingStrategy":"validation","validationCode":"# flag columns that combine default with auto_inc/primary_key/unique\ngrep -rn -A3 'default(' src/ | grep -E 'auto_inc|primary_key|unique' || echo OK","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","proc-macro","spacetimedb","default-value","primary-key","compile-time"],"backgroundTag":"conflicting-attributes","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}