{"record":{"id":"f274ee308e1b6058","repo":"Budibase/budibase","slug":"junction-table-relationship-junctiontable-not","errorCode":null,"errorMessage":"Junction table '${relationship.junctionTable}' not found in datasource","messagePattern":"Junction table '(.+?)' not found in datasource","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts","lineNumber":179,"sourceCode":"    ) {\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      )\n\n      const targetColumnName = generateRelationshipColumnName(\n        targetTable.schema,\n        relationship.sourceTable,\n        relationship.targetColumn\n      )\n\n      // Create many-to-many relationship columns","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts#L161-L197","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure the junction table is included in the import selection so it exists in datasource.entities.","Fix relationship.junctionTable to exactly match a table name present in datasource.entities.","Re-sync the datasource schema so the join table entity is present, then retry."],"exampleFix":"// before\n{ junctionTable: \"UserRoles\" } // table imported as \"user_roles\"\n// after\n{ junctionTable: \"user_roles\" } // must match datasource.entities key exactly","handlingStrategy":"validation","validationCode":"const missing = relationships\n  .filter(r => r.relationshipType === DatasourceRelationshipType.MANY_TO_MANY)\n  .filter(r => r.junctionTable && !datasource.entities[r.junctionTable])\nif (missing.length) throw new Error(`Unknown junction tables: ${missing.map(r => r.junctionTable).join(\", \")}`)","typeGuard":"const junctionExists = (r: Relationship, ds: Datasource): r is Relationship & { junctionTable: string } =>\n  !!r.junctionTable && !!ds.entities[r.junctionTable]","tryCatchPattern":"try {\n  await createRelationshipColumns(...)\n} catch (e) {\n  if (e.message.startsWith(\"Junction table\")) {\n    const name = e.message.match(/'([^']+)'/)?.[1]\n    console.warn(`Junction table ${name} missing; skipping relationship`); return\n  }\n  throw e\n}","preventionTips":["Include the junction table in the tables selected for import.","Match junctionTable names exactly against datasource.entities keys (case-sensitive).","Re-fetch the datasource schema after DB renames so entity names stay current."],"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"}