{"record":{"id":"e273cc7f4ab93fd8","repo":"clockworklabs/SpacetimeDB","slug":"addview-view-view-name-not-found-in-new-modul","errorCode":null,"errorMessage":"AddView: view `{view_name}` not found in new module def","messagePattern":"AddView: view `(.+?)` not found in new module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":299,"sourceCode":"                stdb.drop_table(tx, table_id)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::AddTable(table_name_key) => {\n                let (namespace, local) = table_name_key;\n                let table_name = joined(namespace, local);\n                let (owning_def, table_def) = plan\n                    .new\n                    .find_table(table_name_key)\n                    .ok_or_else(|| anyhow::anyhow!(\"AddTable: table `{table_name}` not found in new module def\"))?;\n                log!(logger, \"Creating table `{table_name}`\");\n                create_table_from_def_with_prefix(stdb, tx, owning_def, table_def, namespace)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::AddView(view_name_key) => {\n                let (namespace, local) = view_name_key;\n                let view_name = joined(namespace, local);\n                let (owning_def, view_def) = plan\n                    .new\n                    .find_view(view_name_key)\n                    .ok_or_else(|| anyhow::anyhow!(\"AddView: view `{view_name}` not found in new module def\"))?;\n                create_table_from_view_def_with_prefix(stdb, tx, owning_def, view_def, namespace)?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::RemoveView(view_name_key) => {\n                let (namespace, local) = view_name_key;\n                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) => {","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L281-L317","documentation":"Auto-migrate step AddView: plan.new.find_view(view_name_key) returned None — the view the plan intends to create is absent from the new module def. As with AddTable, this signals plan/def desynchronization inside the migration machinery.","triggerScenarios":"A migration plan built from a different def than plan.new; view keys with mismatched namespace prefixes; differ bugs emitting AddView for a view not present in the def.","commonSituations":"Reusing cached plans after editing view definitions; upstream schema-diff changes; manual plan construction in tests.","solutions":["Recompute the plan from the same def that provides plan.new","Verify the (namespace, view name) key resolves in the new def","Report upstream if machine-generated plans still trigger it"],"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(\"AddView:\") && e.to_string().contains(\"not found in new module def\") => {\n        anyhow::bail!(\"plan/def desync: {e:#}; regenerate the migration plan from the current defs\");\n    }\n    r => r,\n}","preventionTips":["Regenerate plans whenever view definitions change","Keep namespace prefixes consistent between diff and apply","Cover view add/remove in migration integration tests"],"tags":["rust","spacetimedb","migration","view","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-14T00:17:10.932Z"}