{"record":{"id":"f2c9b8c18e764511","repo":"Budibase/budibase","slug":"junction-table-not-specified-for-many-to-many-rela","errorCode":null,"errorMessage":"Junction table not specified for many-to-many relationship between ${relationship.sourceTable} and ${relationship.targetTable}","messagePattern":"Junction table not specified for many-to-many relationship between (.+?) and (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts","lineNumber":171,"sourceCode":"        : undefined\n    if (\n      relationshipExists(\n        sourceTable,\n        targetTable,\n        relationship,\n        junctionTableId\n      )\n    ) {\n      // Relationship already exists, skip creating it\n      return false\n    }\n\n    if (\n      relationship.relationshipType === DatasourceRelationshipType.MANY_TO_MANY\n    ) {\n      // For many-to-many relationships, we need the junction table\n      if (!relationship.junctionTable) {\n        throw new Error(\n          `Junction table not specified for many-to-many relationship between ${relationship.sourceTable} and ${relationship.targetTable}`\n        )\n      }\n\n      // Get the junction table entity\n      const junctionTable = datasource.entities[relationship.junctionTable]\n      if (!junctionTable) {\n        throw new Error(\n          `Junction table '${relationship.junctionTable}' not found in datasource`\n        )\n      }\n\n      // Generate unique column names\n      const sourceColumnName = generateRelationshipColumnName(\n        sourceTable.schema,\n        relationship.targetTable,\n        relationship.sourceColumn\n      )","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts#L153-L189","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nrelationships.push({ sourceTable: \"users\", targetTable: \"roles\", relationshipType: DatasourceRelationshipType.MANY_TO_MANY })\n// after\nrelationships.push({ sourceTable: \"users\", targetTable: \"roles\", relationshipType: DatasourceRelationshipType.MANY_TO_MANY, junctionTable: \"user_roles\" })","handlingStrategy":"validation","validationCode":"const invalid = relationships.some(r => r.relationshipType === DatasourceRelationshipType.MANY_TO_MANY && !r.junctionTable)\nif (invalid) throw new Error(\"All many-to-many relationships need a junctionTable\")","typeGuard":"const hasJunction = (r: Relationship): r is Relationship & { junctionTable: string } =>\n  r.relationshipType !== DatasourceRelationshipType.MANY_TO_MANY || typeof r.junctionTable === \"string\" && r.junctionTable.length > 0","tryCatchPattern":"try {\n  await createRelationshipColumns(...)\n} catch (e) {\n  if (e.message.includes(\"Junction table not specified\")) {\n    promptUserForJunctionTable(); return\n  }\n  throw e\n}","preventionTips":["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."],"tags":["config","relationships","many-to-many","builder"],"backgroundTag":"missing-junction-table","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}