{"record":{"id":"5ebb22ad5687567c","repo":"Budibase/budibase","slug":"target-table-relationship-targettable-not-fou","errorCode":null,"errorMessage":"Target table '${relationship.targetTable}' not found in datasource","messagePattern":"Target table '(.+?)' not found in datasource","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts","lineNumber":140,"sourceCode":"      return keepOpen\n    }\n  }\n\n  const createRelationshipColumns = async (\n    datasource: Datasource,\n    relationship: DatasourceRelationshipConfig\n  ): Promise<boolean> => {\n    // Ensure the tables exist in the datasource\n    if (!datasource.entities) {\n      datasource.entities = {}\n    }\n    if (!datasource.entities[relationship.sourceTable]) {\n      throw new Error(\n        `Source table '${relationship.sourceTable}' not found in datasource`\n      )\n    }\n    if (!datasource.entities[relationship.targetTable]) {\n      throw new Error(\n        `Target table '${relationship.targetTable}' not found in datasource`\n      )\n    }\n\n    const sourceTable = datasource.entities[relationship.sourceTable]\n    const targetTable = datasource.entities[relationship.targetTable]\n\n    // Check if this relationship already exists\n    const junctionTableId =\n      relationship.relationshipType ===\n        DatasourceRelationshipType.MANY_TO_MANY && relationship.junctionTable\n        ? datasource.entities[relationship.junctionTable]?._id\n        : undefined\n    if (\n      relationshipExists(\n        sourceTable,\n        targetTable,\n        relationship,","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts#L122-L158","documentation":"Same validation as the source table check, but for the relationship's target table: createRelationshipColumns requires datasource.entities[relationship.targetTable] to exist before it can build the join columns on both sides. Thrown when the referenced target table is missing from the datasource metadata.","triggerScenarios":"wasCreated → createRelationshipColumns called with a relationship whose relationship.targetTable key is absent from datasource.entities — target table dropped/renamed externally, entities not fetched, or name/casing mismatch in the stored relationship.","commonSituations":"External database schema changed (target table renamed or deleted) after the relationship was configured in Budibase; partial schema sync leaving entities incomplete; typo in the table name when relationships are defined programmatically or via older configs.","solutions":["Re-fetch/sync the datasource schema so the target table appears in datasource.entities.","Correct relationship.targetTable to the table's current exact name (verify casing against entities keys).","Recreate the relationship if the target table no longer exists in the external database."],"exampleFix":"// before\nrelationship.targetTable = \"Customers\" // dropped and recreated as \"customer\"\n// after\nrelationship.targetTable = \"customer\" // current name in datasource.entities","handlingStrategy":"validation","validationCode":"const assertTablesExist = (ds: Datasource, rel: { sourceTable: string; targetTable: string }) => {\n  if (!ds.entities?.[rel.targetTable]) {\n    throw new Error(`Target table '${rel.targetTable}' missing; refresh datasource schema`)\n  }\n}\nassertTablesExist(datasource, relationship)","typeGuard":"const hasEntity = (ds: Datasource, table: string): ds is Datasource & { entities: Record<typeof table, Table> } =>\n  ds.entities != null && table in ds.entities","tryCatchPattern":"try {\n  await store.wasCreated(datasource, relationship)\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Target table\")) {\n    await refreshDatasourceSchema(datasource)\n    // verify target table exists or prompt user to re-select it\n  } else throw err\n}","preventionTips":["Always fetch fresh entities before validating relationships, never trust cached metadata.","Compare names case-sensitively against Object.keys(datasource.entities).","Detect external schema drift periodically and flag broken relationships."],"tags":["builder","datasource","relationships","validation"],"backgroundTag":"table-not-found-in-datasource","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}