{"record":{"id":"da2b19f9386b1a95","repo":"clockworklabs/SpacetimeDB","slug":"column-col-name-not-found-in-table-table-nam","errorCode":null,"errorMessage":"Column `{col_name}` not found in table `{table_name}`","messagePattern":"Column `(.+?)` not found in table `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":396,"sourceCode":"\n                log!(\n                    logger,\n                    \"Changing table accessor name for `{table_name}` to `{new_alias}`\",\n                );\n                stdb.alter_table_accessor_name(tx, table_id, new_alias)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeColumnAccessorName(table_name_key, col_name) => {\n                let (namespace, local) = table_name_key;\n                let table_name = joined(namespace, local);\n                let (_, new_table_def): (&ModuleDef, &spacetimedb_schema::def::TableDef) =\n                    plan.new.find_table(table_name_key).ok_or_else(|| {\n                        anyhow::anyhow!(\"ChangeColumnAccessorName: `{table_name}` not found in new module def\")\n                    })?;\n                let new_col_def = new_table_def\n                    .columns\n                    .iter()\n                    .find(|col| &col.name == col_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"Column `{col_name}` not found in table `{table_name}`\"))?;\n\n                let table_id = stdb.table_id_from_name_mut(tx, &table_name)?.unwrap();\n                let table_schema = stdb.schema_for_table_mut(tx, table_id)?;\n                let col_schema = table_schema\n                    .columns\n                    .iter()\n                    .find(|col| &col.col_name == col_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"Column `{col_name}` not found in table `{table_name}`\"))?;\n\n                log!(\n                    logger,\n                    \"Changing column accessor name for `{}`.`{}` to `{}`\",\n                    table_name,\n                    col_name,\n                    new_col_def.accessor_name,\n                );\n                stdb.alter_column_accessor_name(tx, table_id, col_schema.col_pos, new_col_def.accessor_name.clone())?;\n            }","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L378-L414","documentation":"During ChangeColumnAccessorName the engine found the table in the new module def but no column whose name equals the step's col_name (new_table_def.columns lookup by col.name). The planner emitted a column-accessor rename keyed by a stored column name that no longer exists in the new definition. The publish aborts.","triggerScenarios":"Changing #[column(name = ...)] (or deleting the column) in the same publish where the column's accessor changed, so the planner's stored-name key misses in the new def; also column-name normalization/casing drift or submodule namespace differences between the def the planner saw and the def being applied.","commonSituations":"Renaming struct fields and their stored names in one commit; switching SDK versions that changed name normalization; copy-pasted column attributes after refactors.","solutions":["Clean-rebuild (cargo clean -p <crate> or delete target/), spacetime build, republish.","Keep the stored column name pinned (#[spacetimedb::column(name = \"hp\")]) and rename only the Rust field; publish that alone.","If the column itself must be renamed, do it in its own publish with nothing else changed.","Align SDK/CLI/server versions with the live database's provenance.","Dev only: spacetime publish --delete-data <db>.","Persistent on clean builds: report as an auto_migrate planner bug with the module diff."],"exampleFix":"// before: stored name AND accessor changed in one publish\npub struct Player {\n    #[spacetimedb::column(name = \"hit_points\")] // stored name was `hp`\n    pub hp: u32,\n}\n\n// after: keep stored name, change accessor only\npub struct Player {\n    #[spacetimedb::column(name = \"hp\")]\n    pub hit_points: u32,\n}","handlingStrategy":"validation","validationCode":"use spacetimedb_schema::auto_migrate::AutoMigrateStep;\nfor step in &plan.steps {\n    if let AutoMigrateStep::ChangeColumnAccessorName(key, col_name) = step {\n        if let Some((_, tdef)) = plan.new.find_table(key) {\n            anyhow::ensure!(\n                tdef.columns.iter().any(|c| &c.name == col_name),\n                \"column {} missing from new def of table {:?}\", col_name, key\n            );\n        }\n    }\n}","typeGuard":"fn column_in_new_def(tdef: &TableDef, col_name: &str) -> bool {\n    tdef.columns.iter().any(|c| c.name == col_name)\n}","tryCatchPattern":"match update_database(&stdb, tx, &plan, ...).await {\n    Err(e) if e.to_string().contains(\"Column `\")\n        && e.to_string().contains(\"not found in table\")\n        && e.to_string().contains(\"ChangeColumnAccessorName\") => {\n        // Column key drift: pin #[column(name)], republish the accessor change alone.\n    }\n    result => result?,\n}","preventionTips":["Pin stored column names with #[column(name = \"...\")] before renaming fields.","Never change a column's stored name and its accessor in the same publish.","Review the generated schema (build artifacts) after renames to confirm keys are unchanged.","Keep one schema change per publish."],"tags":["spacetimedb","rust","schema-migration","publish","column-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"}