Budibase/budibase · error

Source table '${relationship.sourceTable}' not found in data

Error message

Source table '${relationship.sourceTable}' not found in datasource

What it means

When importing tables from an external datasource, relationshipSelectionStore validates that the configured relationship's source table actually exists in datasource.entities before creating relationship columns. This error means the relationship definition references a source table name that the fetched datasource metadata does not contain.

Source

Thrown at packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts:135

      }

      await onComplete()
    } catch (err: any) {
      errorStore.set(err)
      return keepOpen
    }
  }

  const createRelationshipColumns = async (
    datasource: Datasource,
    relationship: DatasourceRelationshipConfig
  ): Promise<boolean> => {
    // Ensure the tables exist in the datasource
    if (!datasource.entities) {
      datasource.entities = {}
    }
    if (!datasource.entities[relationship.sourceTable]) {
      throw new Error(
        `Source table '${relationship.sourceTable}' not found in datasource`
      )
    }
    if (!datasource.entities[relationship.targetTable]) {
      throw new Error(
        `Target table '${relationship.targetTable}' not found in datasource`
      )
    }

    const sourceTable = datasource.entities[relationship.sourceTable]
    const targetTable = datasource.entities[relationship.targetTable]

    // Check if this relationship already exists
    const junctionTableId =
      relationship.relationshipType ===
        DatasourceRelationshipType.MANY_TO_MANY && relationship.junctionTable
        ? datasource.entities[relationship.junctionTable]?._id
        : undefined

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Refresh the datasource schema in the builder so datasource.entities reflects the current external tables.
  2. Update the relationship definition to use the current source table name (check for renames and exact casing).
  3. Re-create the relationship/import if the underlying table was dropped in the external database.
  4. Verify the entities fetch succeeded before running the import (don't proceed with an empty entities map).

Example fix

// before
relationship.sourceTable = "Orders" // table renamed to "orders"
// after
relationship.sourceTable = "orders" // matches datasource.entities key
Defensive patterns

Strategy: validation

Validate before calling

const assertTablesExist = (ds: Datasource, rel: { sourceTable: string; targetTable: string }) => {
  if (!ds.entities?.[rel.sourceTable]) {
    throw new Error(`Source table '${rel.sourceTable}' missing; refresh datasource schema`)
  }
}
assertTablesExist(datasource, relationship)

Type guard

const hasEntity = (ds: Datasource, table: string): ds is Datasource & { entities: Record<typeof table, Table> } =>
  ds.entities != null && table in ds.entities

Try / catch

try {
  await store.wasCreated(datasource, relationship)
} catch (err) {
  if (err instanceof Error && err.message.includes("not found in datasource")) {
    await refreshDatasourceSchema(datasource)
    // retry once with fresh entities
  } else throw err
}

Prevention

When it happens

Trigger: wasCreated → createRelationshipColumns invoked with a relationship whose relationship.sourceTable key is absent from datasource.entities (stale or hand-edited datasource, renamed table, or entities not yet fetched from the external database).

Common situations: The external table was renamed/dropped after the datasource was configured; datasource.entities was never populated because the schema fetch failed or was skipped; casing/key mismatches between the stored relationship name and the entities map keys.

Related errors


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