{"record":{"id":"30921dde8694b63e","repo":"clockworklabs/SpacetimeDB","slug":"addsequence-sequence-name-not-found-in-new-mo","errorCode":null,"errorMessage":"AddSequence: `{sequence_name}` not found in new module def","messagePattern":"AddSequence: `(.+?)` not found in new module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":503,"sourceCode":"                    .table_id_from_name_mut(tx, &table_full_name)?\n                    .expect(\"table should exist in the database for AddConstraint\");\n                let mut constraint_schema =\n                    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","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L485-L521","documentation":"Applying AddSequence: the diff plans creating a sequence (e.g. from #[auto_inc] columns), but no table in the new module def stores it (plan.new.find_storing_table returns None). The sequence key does not resolve in the new defs - plan/def desync. The publish aborts before the sequence is created.","triggerScenarios":"Adding #[auto_inc]/sequence columns while renaming the table or the sequenced column in the same publish; sequence auto-name drift between the def the planner saw and the def being applied (different SDK/compiler versions).","commonSituations":"Introducing auto-increment IDs during a table refactor; version upgrades between publishes; submodule moves of tables gaining sequences.","solutions":["Clean-rebuild and republish.","Add the sequence/auto_inc column in its own publish with the table otherwise unchanged.","Keep the owning table's stored name and module path stable; pin with #[table(name = \"...\")].","Align toolchain versions across builds publishing the same database.","Dev: spacetime publish --delete-data <db>.","Report persistent cases with the module diff."],"exampleFix":"// before: add #[auto_inc] and rename the table in one publish\n#[spacetimedb::table(name = \"members\")] // was `players`\npub struct Member { #[auto_inc] pub id: u64 }\n\n// after: two publishes\n// 1) #[spacetimedb::table(name = \"players\")] struct Player { #[auto_inc] pub id: u64 }\n// 2) rename the table separately","handlingStrategy":"validation","validationCode":"use spacetimedb_schema::auto_migrate::AutoMigrateStep;\nfor step in &plan.steps {\n    if let AutoMigrateStep::AddSequence((namespace, sname)) = step {\n        if plan.new.find_storing_table(namespace, sname).is_none() {\n            anyhow::bail!(\"new def lacks storing table for sequence {}\", sname);\n        }\n    }\n}","typeGuard":"fn sequence_stores_in_new_def(plan: &AutoMigratePlan, ns: &str, sname: &str) -> bool {\n    plan.new.find_storing_table(ns, sname).is_some()\n}","tryCatchPattern":"match update_database(&stdb, tx, &plan, ...).await {\n    Err(e) if e.to_string().contains(\"AddSequence\")\n        && e.to_string().contains(\"not found in new module def\") => {\n        // Split publishes: add auto_inc with the table unchanged; refactor later.\n    }\n    result => result?,\n}","preventionTips":["Add #[auto_inc]/sequence columns in their own publish.","Keep the owning table's name and module path stable during the change.","Align toolchain versions across build environments.","Clean-rebuild after SDK upgrades."],"tags":["spacetimedb","rust","schema-migration","sequence","auto-increment","publish"],"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-14T05:17:10.506Z"}