Budibase/budibase · error

Junction table '${relationship.junctionTable}' not found in

Error message

Junction table '${relationship.junctionTable}' not found in datasource

What it means

After confirming junctionTable is set, createRelationshipColumns looks the junction table up in datasource.entities. If the named table does not exist in the datasource being imported, it throws this error. The check prevents generating relationship columns that reference a non-existent table.

Source

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

    ) {
      // Relationship already exists, skip creating it
      return false
    }

    if (
      relationship.relationshipType === DatasourceRelationshipType.MANY_TO_MANY
    ) {
      // For many-to-many relationships, we need the junction table
      if (!relationship.junctionTable) {
        throw new Error(
          `Junction table not specified for many-to-many relationship between ${relationship.sourceTable} and ${relationship.targetTable}`
        )
      }

      // Get the junction table entity
      const junctionTable = datasource.entities[relationship.junctionTable]
      if (!junctionTable) {
        throw new Error(
          `Junction table '${relationship.junctionTable}' not found in datasource`
        )
      }

      // Generate unique column names
      const sourceColumnName = generateRelationshipColumnName(
        sourceTable.schema,
        relationship.targetTable,
        relationship.sourceColumn
      )

      const targetColumnName = generateRelationshipColumnName(
        targetTable.schema,
        relationship.sourceTable,
        relationship.targetColumn
      )

      // Create many-to-many relationship columns

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Ensure the junction table is included in the import selection so it exists in datasource.entities.
  2. Fix relationship.junctionTable to exactly match a table name present in datasource.entities.
  3. Re-sync the datasource schema so the join table entity is present, then retry.

Example fix

// before
{ junctionTable: "UserRoles" } // table imported as "user_roles"
// after
{ junctionTable: "user_roles" } // must match datasource.entities key exactly
Defensive patterns

Strategy: validation

Validate before calling

const missing = relationships
  .filter(r => r.relationshipType === DatasourceRelationshipType.MANY_TO_MANY)
  .filter(r => r.junctionTable && !datasource.entities[r.junctionTable])
if (missing.length) throw new Error(`Unknown junction tables: ${missing.map(r => r.junctionTable).join(", ")}`)

Type guard

const junctionExists = (r: Relationship, ds: Datasource): r is Relationship & { junctionTable: string } =>
  !!r.junctionTable && !!ds.entities[r.junctionTable]

Try / catch

try {
  await createRelationshipColumns(...)
} catch (e) {
  if (e.message.startsWith("Junction table")) {
    const name = e.message.match(/'([^']+)'/)?.[1]
    console.warn(`Junction table ${name} missing; skipping relationship`); return
  }
  throw e
}

Prevention

When it happens

Trigger: relationship.junctionTable is set (so error 80 passes) but datasource.entities[relationship.junctionTable] is undefined — the join table name in the relationship definition does not match any imported table's name (typo, renamed table, or table not selected for import).

Common situations: Typos in junctionTable names; the junction table was excluded from the selected tables during import; table renamed in the database after relationships were captured; case-sensitivity mismatch between DB name and entities key.

Related errors


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