{"record":{"id":"7831dd50c27017e3","repo":"Budibase/budibase","slug":"unable-to-find-related-table","errorCode":null,"errorMessage":"unable to find related table","messagePattern":"unable to find related table","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/api/controllers/row/ExternalRequest.ts","lineNumber":465,"sourceCode":"        fieldName = field.throughTo || primaryKey\n      } else if (isManyToOne(field)) {\n        relatedTableId = field.tableId\n        lookupField = field.foreignKey\n        fieldName = field.fieldName\n      }\n      if (!relatedTableId || !lookupField || !fieldName) {\n        throw new Error(\n          \"Unable to lookup relationships - undefined column properties.\"\n        )\n      }\n\n      if (!lookupField || !row?.[lookupField]) {\n        continue\n      }\n      const endpoint = getEndpoint(relatedTableId, Operation.READ)\n      const relatedTable = this.tables[endpoint.entityId]\n      if (!relatedTable) {\n        throw new Error(\"unable to find related table\")\n      }\n      const response = await makeExternalQuery({\n        endpoint,\n        filters: {\n          equal: {\n            [fieldName]: row[lookupField],\n          },\n        },\n      })\n      // this is the response from knex if no rows found\n      const rows: Row[] =\n        !Array.isArray(response) || isKnexEmptyReadResponse(response)\n          ? []\n          : response\n\n      const relatedKey = this.getLookupRelationsKey(field)\n      related[relatedKey] = {\n        rows,","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/row/ExternalRequest.ts#L447-L483","documentation":"After resolving a relationship column, lookupRelations looks up the related table in this.tables (the tables loaded from the datasource). If the related tableId is not present in the loaded table set, it throws. This means the relationship points at a table the datasource does not currently expose.","triggerScenarios":"Calling related() where the relationship column's tableId references a table that is not loaded: the related table was dropped from the datasource selection, deleted from the external DB, or the ID is stale after a schema change.","commonSituations":"Fetching related rows after removing a table from the datasource's table list; DB table renamed/dropped while Budibase schema is stale; cross-datasource relationship (not supported) leaving the table absent from this.tables.","solutions":["Re-sync/re-fetch the datasource so this.tables includes the related table","Ensure the related table is selected/connected in the datasource configuration","Update or remove relationships pointing at tables that no longer exist"],"exampleFix":"// before\n// related table dropped from datasource tables list\nawait externalRequest.related(row, table)\n// after\nif (!externalRequest.tables[breakExternalTableId(field.tableId).tableName]) {\n  await datasource.sync()\n}\nawait externalRequest.related(row, table)","handlingStrategy":"validation","validationCode":"const relatedName = breakExternalTableId(field.tableId).tableName\nif (!externalRequest.tables[relatedName]) {\n  throw new Error(`Related table ${relatedName} not in datasource; sync the datasource first`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await externalRequest.related(row, table)\n} catch (err) {\n  if ((err as Error).message === \"unable to find related table\") {\n    await datasource.sync()\n    return await externalRequest.related(row, table)\n  }\n  throw err\n}","preventionTips":["Keep all related tables selected in the datasource configuration","Sync the datasource after adding/renaming tables in the external DB","Avoid relationships spanning different datasources"],"tags":["server","external-datasource","relationships","stale-schema"],"backgroundTag":"related-table-missing","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}