{"record":{"id":"d4c9c4e4c6106ac7","repo":"clockworklabs/SpacetimeDB","slug":"addindex-index-name-not-found-in-new-module-d","errorCode":null,"errorMessage":"AddIndex: `{index_name}` not found in new module def","messagePattern":"AddIndex: `(.+?)` not found in new module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":322,"sourceCode":"                let view_name = joined(namespace, local);\n                let view_id = stdb\n                    .view_id_from_name_mut(tx, &view_name)?\n                    .ok_or_else(|| anyhow::anyhow!(\"RemoveView: view `{view_name}` not found in database\"))?;\n                stdb.drop_view(tx, view_id)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::UpdateView(_) => {\n                // if we already have to disconnect clients, no need to set\n                // `EvaluateSubscribedViews` as clients will be disconnected anyway\n                if !matches!(res, UpdateResult::RequiresClientDisconnect) {\n                    res = UpdateResult::EvaluateSubscribedViews;\n                }\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::AddIndex(key) => {\n                let (namespace, index_name) = key;\n                let (owning_def, table_def) = plan\n                    .new\n                    .find_storing_table(namespace, index_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"AddIndex: `{index_name}` not found in new module def\"))?;\n                let table_full_name = joined(namespace, &table_def.name);\n                let index_def: &IndexDef = plan\n                    .new\n                    .lookup(key)\n                    .ok_or_else(|| anyhow::anyhow!(\"AddIndex: index `{index_name}` not found in new module def\"))?;\n                let table_id = stdb.table_id_from_name_mut(tx, &table_full_name)?.unwrap();\n\n                let index_cols = ColSet::from(index_def.algorithm.columns());\n\n                let is_unique = table_def\n                    .constraints\n                    .iter()\n                    .filter_map(|(_, c)| c.data.unique_columns())\n                    .any(|unique_cols| unique_cols == &index_cols);\n\n                log!(logger, \"Creating index `{index_name}` on table `{table_full_name}`\");\n\n                let mut index_schema = IndexSchema::from_module_def(owning_def, index_def, table_id, 0.into());","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L304-L340","documentation":"Auto-migrate step AddIndex: find_storing_table(namespace, index_name) failed — no table in the new module def stores the index named in the step. The plan references an index whose owning table is absent from plan.new; an internal plan/def inconsistency.","triggerScenarios":"AddIndex step generated from a different def revision than plan.new; index-to-table association changed between diff and apply; hand-built plans with dangling index keys.","commonSituations":"Cached plans reused after def edits; upstream differ bugs; submodule index namespace mismatches.","solutions":["Regenerate the plan from the same def that provides plan.new","Check the (namespace, index name) key resolves to a storing table in the new def","Report upstream if the differ produced the dangling step"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match auto_migrate_database(&stdb, &mut tx, auth, &plan, &logger) {\n    Err(e) if e.to_string().contains(\"AddIndex:\") && e.to_string().contains(\"not found in new module def\") => {\n        anyhow::bail!(\"plan/def desync: {e:#}; regenerate the plan from one consistent def\");\n    }\n    r => r,\n}","preventionTips":["Derive index steps and def lookups from the same def revision","Keep index-to-table associations stable between diff and apply","Test index add/remove paths in migration integration tests"],"tags":["rust","spacetimedb","migration","index","internal-invariant"],"backgroundTag":"migration-plan-invalid","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"}