{"record":{"id":"b36f9948326533af","repo":"clockworklabs/SpacetimeDB","slug":"addsequence-sequence-sequence-name-not-found","errorCode":null,"errorMessage":"AddSequence: sequence `{sequence_name}` not found in new module def","messagePattern":"AddSequence: sequence `(.+?)` not found in new module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":506,"sourceCode":"                    ConstraintSchema::from_module_def(owning_def, constraint_def, table_id, ConstraintId::SENTINEL);\n\n                // Apply namespace prefix for submodule constraints\n                constraint_schema.constraint_name = namespace.join_raw(&constraint_schema.constraint_name);\n                log!(\n                    logger,\n                    \"Adding constraint `{constraint_name}` on table `{table_full_name}`\"\n                );\n                stdb.create_constraint(tx, constraint_schema)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::AddSequence(key) => {\n                let (namespace, sequence_name) = key;\n                let (owning_def, table_def) = plan\n                    .new\n                    .find_storing_table(namespace, sequence_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"AddSequence: `{sequence_name}` not found in new module def\"))?;\n                let table_full_name = joined(namespace, &table_def.name);\n                let sequence_def: &SequenceDef = plan.new.lookup(key).ok_or_else(|| {\n                    anyhow::anyhow!(\"AddSequence: sequence `{sequence_name}` not found in new module def\")\n                })?;\n                let table_id = stdb.table_id_from_name_mut(tx, &table_full_name)?.unwrap();\n                let table_schema = stdb.schema_for_table_mut(tx, table_id)?;\n\n                log!(logger, \"Adding sequence `{sequence_name}` to table `{table_full_name}`\");\n                let mut sequence_schema =\n                    SequenceSchema::from_module_def(owning_def, sequence_def, table_schema.table_id, 0.into());\n\n                // Apply namespace prefix for submodule sequences\n                sequence_schema.sequence_name = namespace.join_raw(&sequence_schema.sequence_name);\n                stdb.create_sequence(tx, sequence_schema)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::RemoveSequence(key) => {\n                let (namespace, sequence_name) = key;\n                let (_owning_def, table_def) = plan\n                    .old\n                    .find_storing_table(namespace, sequence_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"RemoveSequence: `{sequence_name}` not found in old module def\"))?;","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L488-L524","documentation":"AddSequence resolved the storing table, but plan.new.lookup::<SequenceDef>(key) returned None: the sequence is not registered as a lookupable entity in the new module def set although the table references it. The def set's entity registry and table-level sequence references are inconsistent (namespace-key drift for submodules, or mismatched macro versions). The publish aborts.","triggerScenarios":"Sequences on tables inside submodules whose registration namespace differs from the table's; defs produced by two different SDK macro versions so the table's sequence map and the registry disagree.","commonSituations":"Auto-increment columns on submodule tables; upgrading the SDK between builds; incremental builds mixing artifacts from two toolchains.","solutions":["Full clean rebuild (delete target/ entirely), spacetime build, republish.","Add the sequence while the table sits at the crate root; move it into the submodule in a later publish.","Verify a single SDK version in the tree: cargo tree -i spacetimedb.","Dev: spacetime publish --delete-data <db>.","Report as a def-indexing bug with the submodule layout."],"exampleFix":"// before: auto_inc on a submodule table; registry lookup misses\nmod guild {\n    #[spacetimedb::table(name = \"members\")]\n    pub struct Member { #[auto_inc] pub id: u64 }\n}\n\n// after: add the sequence at the root first\n#[spacetimedb::table(name = \"members\")]\npub struct Member { #[auto_inc] pub id: u64 }","handlingStrategy":"validation","validationCode":"use spacetimedb_schema::auto_migrate::AutoMigrateStep;\nuse spacetimedb_schema::def::SequenceDef;\nfor step in &plan.steps {\n    if let AutoMigrateStep::AddSequence(key) = step {\n        anyhow::ensure!(\n            plan.new.lookup::<SequenceDef>(key).is_some(),\n            \"sequence {:?} missing from the new def registry\", key\n        );\n    }\n}","typeGuard":"fn sequence_registered(plan: &AutoMigratePlan, key: (&str, &str)) -> bool {\n    plan.new.lookup::<SequenceDef>(key).is_some()\n}","tryCatchPattern":"match update_database(&stdb, tx, &plan, ...).await {\n    Err(e) if e.to_string().contains(\"AddSequence: sequence\") => {\n        // Def registry desync: full clean rebuild; add the sequence at a stable module path.\n    }\n    result => result?,\n}","preventionTips":["Add sequences while the table is at the crate root or a stable path; move it later.","Verify only one SDK/macro version exists in the dependency tree.","Avoid incremental builds across toolchain upgrades."],"tags":["spacetimedb","rust","schema-migration","sequence","submodule","namespace"],"backgroundTag":"schema-migration-plan-mismatch","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}