Budibase/budibase · error

unable to find related table

Error message

unable to find related table

What it means

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.

Source

Thrown at packages/server/src/api/controllers/row/ExternalRequest.ts:465

        fieldName = field.throughTo || primaryKey
      } else if (isManyToOne(field)) {
        relatedTableId = field.tableId
        lookupField = field.foreignKey
        fieldName = field.fieldName
      }
      if (!relatedTableId || !lookupField || !fieldName) {
        throw new Error(
          "Unable to lookup relationships - undefined column properties."
        )
      }

      if (!lookupField || !row?.[lookupField]) {
        continue
      }
      const endpoint = getEndpoint(relatedTableId, Operation.READ)
      const relatedTable = this.tables[endpoint.entityId]
      if (!relatedTable) {
        throw new Error("unable to find related table")
      }
      const response = await makeExternalQuery({
        endpoint,
        filters: {
          equal: {
            [fieldName]: row[lookupField],
          },
        },
      })
      // this is the response from knex if no rows found
      const rows: Row[] =
        !Array.isArray(response) || isKnexEmptyReadResponse(response)
          ? []
          : response

      const relatedKey = this.getLookupRelationsKey(field)
      related[relatedKey] = {
        rows,

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Re-sync/re-fetch the datasource so this.tables includes the related table
  2. Ensure the related table is selected/connected in the datasource configuration
  3. Update or remove relationships pointing at tables that no longer exist

Example fix

// before
// related table dropped from datasource tables list
await externalRequest.related(row, table)
// after
if (!externalRequest.tables[breakExternalTableId(field.tableId).tableName]) {
  await datasource.sync()
}
await externalRequest.related(row, table)
Defensive patterns

Strategy: validation

Validate before calling

const relatedName = breakExternalTableId(field.tableId).tableName
if (!externalRequest.tables[relatedName]) {
  throw new Error(`Related table ${relatedName} not in datasource; sync the datasource first`)
}

Try / catch

try {
  return await externalRequest.related(row, table)
} catch (err) {
  if ((err as Error).message === "unable to find related table") {
    await datasource.sync()
    return await externalRequest.related(row, table)
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/7831dd50c27017e3. Report an issue: GitHub.