{"record":{"id":"e25f79fb1fdd90cf","repo":"clockworklabs/SpacetimeDB","slug":"changecolumns-table-table-name-not-found-in-n","errorCode":null,"errorMessage":"ChangeColumns: table `{table_name}` not found in new module def","messagePattern":"ChangeColumns: table `(.+?)` not found in new module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":545,"sourceCode":"                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;\n                let table_name = joined(namespace, local);\n                let (owning_def, table_def) = plan.new.find_table(table_name_key).ok_or_else(|| {\n                    anyhow::anyhow!(\"ChangeColumns: table `{table_name}` not found in new module def\")\n                })?;\n                let table_id = stdb.table_id_from_name_mut(tx, &table_name).unwrap().unwrap();\n                let column_schemas = column_schemas_from_defs(owning_def, &table_def.columns, table_id);\n\n                log!(logger, \"Changing columns of table `{table_name}`\");\n\n                stdb.alter_table_row_type(tx, table_id, column_schemas)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::ReschemaEventTable(table_name_key) => {\n                let (namespace, local) = table_name_key;\n                let table_name = joined(namespace, local);\n                let (owning_def, table_def) = plan.new.find_table(table_name_key).ok_or_else(|| {\n                    anyhow::anyhow!(\"ReschemaEventTable: table `{table_name}` not found in new module def\")\n                })?;\n                let table_id = stdb.table_id_from_name_mut(tx, &table_name).unwrap().unwrap();\n                let column_schemas = column_schemas_from_defs(owning_def, &table_def.columns, table_id);\n\n                log!(logger, \"Changing schema of event table `{}`\", table_name);","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L527-L563","documentation":"Applying AutoMigrateStep::ChangeColumns, which replaces a table's row type after column additions/removals/type changes: plan.new.find_table fails, so the replacement column schemas cannot be built. The step's table key does not resolve in the new module def - plan/def desync. The publish aborts before alter_table_row_type runs.","triggerScenarios":"Changing a table's columns (types, adds, drops) while renaming, moving, or deleting the table in the same publish; or the def set being applied differs from the one the planner diffed (stale build artifacts, mismatched compiler/SDK versions).","commonSituations":"Squashed feature branches combining column changes with table renames; CI publishing with a different toolchain; incremental builds after SDK upgrades.","solutions":["Clean-rebuild and republish.","Split the publish: apply column changes with the table name/location untouched first, then rename/move.","Pin the stored name with #[table(name = \"...\")] and keep it stable across the migration.","Align SDK/CLI/server versions with the live database's provenance.","Dev: spacetime publish --delete-data <db>.","Report as a planner bug if a clean split publish still triggers it."],"exampleFix":"// before: rename + column add in one publish\n#[spacetimedb::table(name = \"members\")] // was \"players\"\npub struct Member { pub level: u32 /* new column */ }\n\n// after: two publishes\n// 1) add the column, keep the name\n#[spacetimedb::table(name = \"players\")]\npub struct Player { pub level: u32 }\n// 2) rename the table separately","handlingStrategy":"validation","validationCode":"use spacetimedb_schema::auto_migrate::AutoMigrateStep;\nfor step in &plan.steps {\n    if let AutoMigrateStep::ChangeColumns(key) = step {\n        if plan.new.find_table(key).is_none() {\n            anyhow::bail!(\"ChangeColumns step references table {:?} missing from new def\", key);\n        }\n    }\n}","typeGuard":"fn table_in_new_def(plan: &AutoMigratePlan, key: (&str, &str)) -> bool {\n    plan.new.find_table(key).is_some()\n}","tryCatchPattern":"match update_database(&stdb, tx, &plan, ...).await {\n    Err(e) if e.to_string().contains(\"ChangeColumns\")\n        && e.to_string().contains(\"not found in new module def\") => {\n        // Split: publish column changes with a stable table name; rename afterwards.\n    }\n    result => result?,\n}","preventionTips":["Never mix column type/add/drop changes with table renames in one publish.","Pin table names with #[table(name = \"...\")] before evolving columns.","Clean-build before publishing after toolchain changes.","One logical schema change per publish."],"tags":["spacetimedb","rust","schema-migration","columns","publish","table-rename"],"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"}