{"record":{"id":"aad9543d5f8fbe95","repo":"Budibase/budibase","slug":"db-does-not-exist","errorCode":null,"errorMessage":"DB does not exist","messagePattern":"DB does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/backend-core/src/db/couch/DatabaseImpl.ts","lineNumber":160,"sourceCode":"    } catch {\n      return false\n    }\n  }\n\n  private nano() {\n    return this.instanceNano || DatabaseImpl.nano\n  }\n\n  private getDb() {\n    return this.nano().db.use(this.name)\n  }\n\n  private async checkAndCreateDb() {\n    let shouldCreate = !this.pouchOpts?.skip_setup\n    // check exists in a lightweight fashion\n    let exists = await this.exists()\n    if (!shouldCreate && !exists) {\n      throw new Error(\"DB does not exist\")\n    }\n    if (!exists) {\n      try {\n        await this.nano().db.create(this.name)\n      } catch (err: any) {\n        // Handling race conditions\n        if (err.statusCode !== 412) {\n          throw new CouchDBError(err.message, err)\n        }\n      }\n    }\n    return this.getDb()\n  }\n\n  // this function fetches the DB and handles if DB creation is needed\n  private async performCallWithDBCreation<T>(\n    call: DBCallback<T>\n  ): Promise<any> {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/backend-core/src/db/couch/DatabaseImpl.ts#L142-L178","documentation":"DatabaseImpl.checkAndCreateDb checks whether the underlying CouchDB database exists. When instance creation is disabled via skip_setup and the DB is absent, it throws instead of silently creating it. This prevents code from operating on databases that were never provisioned.","triggerScenarios":"Constructing/opening a Database with pouchOpts.skip_setup=true (the default for workspace DBs) while the named DB does not exist in CouchDB; e.g. opening an app DB that was deleted or never created.","commonSituations":"Pointing at a fresh CouchDB instance without running provisioning/migrations, typos in DB names, apps deleted while background jobs still reference them, restore/backup gaps.","solutions":["Ensure the DB is created through the normal provisioning path (create the app/workspace) before accessing it","If creation is intended, drop skip_setup so checkAndCreateDb creates the DB","Verify CouchDB connection settings/replicas — the DB may exist on another node/instance","Check for typos in the DB name and that the right tenant/environment is targeted"],"exampleFix":"// before\nconst db = new DatabaseImpl(name, { skip_setup: true })\n// after\nconst db = new DatabaseImpl(name) // allow auto-create\nawait db.exists() ? null : await db.checkAndCreateDb()","handlingStrategy":"fallback","validationCode":"const db = getDB(name, { skip_setup: true })\nif (!(await db.exists())) {\n  // provision or fail fast before real work\n}","typeGuard":null,"tryCatchPattern":"try {\n  await db.put(doc)\n} catch (err) {\n  if (err.message === \"DB does not exist\") {\n    // create the DB via provisioning path, then retry\n  } else throw err\n}","preventionTips":["Always provision DBs through the app/workspace creation flow","Avoid skip_setup unless intentionally read-only","Monitor CouchDB for unexpected DB deletions"],"tags":["couchdb","database","missing-database"],"backgroundTag":"database-does-not-exist","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}