Budibase/budibase · error
Junction table not specified for many-to-many relationship b
Error message
Junction table not specified for many-to-many relationship between ${relationship.sourceTable} and ${relationship.targetTable} What it means
createRelationshipColumns in the builder's relationshipSelectionStore builds columns for imported table relationships. For MANY_TO_MANY relationships it needs a junction (join) table; if relationship.junctionTable is falsy it cannot wire the columns, so it throws this error. It is a configuration-completeness check before any datasource mutation happens.
Source
Thrown at packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts:171
: undefined
if (
relationshipExists(
sourceTable,
targetTable,
relationship,
junctionTableId
)
) {
// 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
)View on GitHub (pinned to a81a902e9a)
Solutions
- Set relationship.junctionTable to the name of the existing join table in datasource.entities before calling createRelationshipColumns.
- If the relationship is actually one-to-many, change relationshipType from MANY_TO_MANY so no junction table is required.
- Create or import the junction table so it exists in datasource.entities, then retry the import.
Example fix
// before
relationships.push({ sourceTable: "users", targetTable: "roles", relationshipType: DatasourceRelationshipType.MANY_TO_MANY })
// after
relationships.push({ sourceTable: "users", targetTable: "roles", relationshipType: DatasourceRelationshipType.MANY_TO_MANY, junctionTable: "user_roles" }) Defensive patterns
Strategy: validation
Validate before calling
const invalid = relationships.some(r => r.relationshipType === DatasourceRelationshipType.MANY_TO_MANY && !r.junctionTable)
if (invalid) throw new Error("All many-to-many relationships need a junctionTable") Type guard
const hasJunction = (r: Relationship): r is Relationship & { junctionTable: string } =>
r.relationshipType !== DatasourceRelationshipType.MANY_TO_MANY || typeof r.junctionTable === "string" && r.junctionTable.length > 0 Try / catch
try {
await createRelationshipColumns(...)
} catch (e) {
if (e.message.includes("Junction table not specified")) {
promptUserForJunctionTable(); return
}
throw e
} Prevention
- Always populate junctionTable when building MANY_TO_MANY relationships from schema introspection.
- Validate relationship definitions against datasource.entities before calling the import flow.
- Let the relationship selection UI derive the junction table instead of constructing payloads manually.
When it happens
Trigger: Calling createRelationshipColumns (via wasCreated) with a relationship whose relationshipType is DatasourceRelationshipType.MANY_TO_MANY and whose junctionTable property is undefined/empty string — e.g. an import payload built outside the relationship selection UI that omitted the junction table.
Common situations: Importing SQL table schemas where join tables were not detected/mapped; hand-crafted or migrated relationship definitions copied from another datasource that lacked junctionTable; UI flows bypassed programmatically so the junction-table picker was never completed.
Related errors
- Junction table '${relationship.junctionTable}' not found in
- Source table '${relationship.sourceTable}' not found in data
- Target table '${relationship.targetTable}' not found in data
- Unknown plugin type - check schema.json: ${schema.type}
- Cannot render an empty flow chain
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/f2c9b8c18e764511.
Report an issue: GitHub.