{"record":{"id":"771ad29b392f9d7e","repo":"clockworklabs/SpacetimeDB","slug":"removesequence-sequence-name-not-found-in-old","errorCode":null,"errorMessage":"RemoveSequence: `{sequence_name}` not found in old module def","messagePattern":"RemoveSequence: `(.+?)` not found in old module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":524,"sourceCode":"                    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\"))?;\n                let table_full_name = joined(namespace, &table_def.name);\n                let stored_name = namespace.join_raw(&sequence_name.clone().into());\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                let sequence_schema = table_schema\n                    .sequences\n                    .iter()\n                    .find(|sequence| sequence.sequence_name == stored_name)\n                    .unwrap();\n\n                log!(\n                    logger,\n                    \"Dropping sequence `{sequence_name}` from table `{table_full_name}`\"\n                );\n                stdb.drop_sequence(tx, sequence_schema.sequence_id)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeColumns(table_name_key) => {\n                let (namespace, local) = table_name_key;","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L506-L542","documentation":"Dropping a sequence: plan.old.find_storing_table cannot find the owning table in the old module def, although the diff planned the removal. The old-def reconstruction disagrees with the database's actual history - the sequence existed in the database but not under a key the old def can resolve. The publish aborts.","triggerScenarios":"Removing #[auto_inc] columns/sequences while also renaming the table in the same publish; the database was published by a build with different sequence auto-naming; submodule moves changing the namespace key between publishes.","commonSituations":"Dropping auto-increment IDs during table renames; version upgrades that changed sequence naming; republishing databases created by older compilers.","solutions":["Clean-rebuild and republish.","Remove the auto_inc column in its own publish; rename/move the table in another.","Keep table names pinned across the versions involved.","Match the toolchain that published the live database before removing sequences.","Dev: spacetime publish --delete-data <db>.","Report with the sequence and table names if it persists."],"exampleFix":"// before: drop #[auto_inc] and rename the table in one publish\n#[spacetimedb::table(name = \"members\")] // was `players`\npub struct Member { pub id: u64 } // #[auto_inc] removed\n\n// after: two publishes\n// 1) remove #[auto_inc] only, name still `players`\n// 2) rename the table separately","handlingStrategy":"fallback","validationCode":"use spacetimedb_schema::auto_migrate::AutoMigrateStep;\nfor step in &plan.steps {\n    if let AutoMigrateStep::RemoveSequence((namespace, sname)) = step {\n        if plan.old.find_storing_table(namespace, sname).is_none() {\n            anyhow::bail!(\"old def lacks sequence {} - schema drift\", sname);\n        }\n    }\n}","typeGuard":"fn sequence_in_old_def(plan: &AutoMigratePlan, ns: &str, sname: &str) -> bool {\n    plan.old.find_storing_table(ns, sname).is_some()\n}","tryCatchPattern":"match update_database(&stdb, tx, &plan, ...).await {\n    Err(e) if e.to_string().contains(\"RemoveSequence\")\n        && e.to_string().contains(\"old module def\") => {\n        // Fall back: publish the exact prior build, then drop the sequence in its own publish.\n    }\n    result => result?,\n}","preventionTips":["Remove auto_inc/sequence columns in a dedicated publish with no renames.","Keep table names pinned across the versions involved.","Match the toolchain that published the live database before removing sequences.","Clean-build between publishes after version changes."],"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"}