{"record":{"id":"56e311e1af160481","repo":"clockworklabs/SpacetimeDB","slug":"removeview-view-view-name-not-found-in-databa","errorCode":null,"errorMessage":"RemoveView: view `{view_name}` not found in database","messagePattern":"RemoveView: view `(.+?)` not found in database","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":307,"sourceCode":"                    .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) => {\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","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L289-L325","documentation":"Auto-migrate step RemoveView: view_id_from_name_mut found no view with the plan's name in the database. The plan (built from the old def) believes the view exists, but the live database does not have it — the database schema and the old module def have drifted.","triggerScenarios":"The view was already dropped in the database (earlier failed migration, manual DDL) while the old def still lists it; view name/prefix mismatch between the plan key and the stored name; stale migration plan computed against an outdated def.","commonSituations":"Retrying a migration after a partially applied earlier one; mixing manual SQL view drops with module publishes; namespace-prefix differences for submodule views.","solutions":["Refresh the old module def from the database's actual state and regenerate the plan","If the view is genuinely gone, remove the stale RemoveView step (or republish the module cleanly)","For disposable databases, publish to a fresh database instead of reconciling drift"],"exampleFix":"// before: apply a plan whose RemoveView targets a nonexistent view\nupdate_database(&stdb, &mut tx, auth, plan, &logger)?;\n\n// after: pre-check the view exists before planning its removal\nif stdb.view_id_from_name_mut(&mut tx, &view_name)?.is_none() {\n    log::warn!(\"view {view_name} already absent; skipping\");\n}","handlingStrategy":"validation","validationCode":"// Before planning a view removal, confirm it exists in the DB\nmatch stdb.view_id_from_name_mut(&mut tx, &view_name)? {\n    Some(_) => { /* plan RemoveView */ }\n    None => log::warn!(\"view {view_name} already absent; skipping removal\"),\n}","typeGuard":"fn view_exists(stdb: &RelationalDB, tx: &mut MutTx, name: &str) -> bool {\n    stdb.view_id_from_name_mut(tx, name).ok().flatten().is_some()\n}","tryCatchPattern":"match auto_migrate_database(&stdb, &mut tx, auth, &plan, &logger) {\n    Err(e) if e.to_string().contains(\"RemoveView:\") && e.to_string().contains(\"not found in database\") => {\n        // schema drift: refresh the old def from the DB and regenerate the plan\n        anyhow::bail!(\"drift detected: {e:#}; rebuild the plan from the database's actual schema\");\n    }\n    r => r,\n}","preventionTips":["Avoid dropping views manually when modules manage them","After a failed migration, refresh defs before retrying","Publish fresh databases in tests rather than reusing drifted fixtures"],"tags":["rust","spacetimedb","migration","view","schema-drift"],"backgroundTag":"migration-schema-mismatch","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"}