{"record":{"id":"7d95375fd46dac38","repo":"Budibase/budibase","slug":"source-table-relationship-sourcetable-not-fou","errorCode":null,"errorMessage":"Source table '${relationship.sourceTable}' not found in datasource","messagePattern":"Source table '(.+?)' not found in datasource","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts","lineNumber":135,"sourceCode":"      }\n\n      await onComplete()\n    } catch (err: any) {\n      errorStore.set(err)\n      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","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/components/backend/Datasources/TableImportSelection/relationshipSelectionStore.ts#L117-L153","documentation":"When importing tables from an external datasource, relationshipSelectionStore validates that the configured relationship's source table actually exists in datasource.entities before creating relationship columns. This error means the relationship definition references a source table name that the fetched datasource metadata does not contain.","triggerScenarios":"wasCreated → createRelationshipColumns invoked with a relationship whose relationship.sourceTable key is absent from datasource.entities (stale or hand-edited datasource, renamed table, or entities not yet fetched from the external database).","commonSituations":"The external table was renamed/dropped after the datasource was configured; datasource.entities was never populated because the schema fetch failed or was skipped; casing/key mismatches between the stored relationship name and the entities map keys.","solutions":["Refresh the datasource schema in the builder so datasource.entities reflects the current external tables.","Update the relationship definition to use the current source table name (check for renames and exact casing).","Re-create the relationship/import if the underlying table was dropped in the external database.","Verify the entities fetch succeeded before running the import (don't proceed with an empty entities map)."],"exampleFix":"// before\nrelationship.sourceTable = \"Orders\" // table renamed to \"orders\"\n// after\nrelationship.sourceTable = \"orders\" // matches datasource.entities key","handlingStrategy":"validation","validationCode":"const assertTablesExist = (ds: Datasource, rel: { sourceTable: string; targetTable: string }) => {\n  if (!ds.entities?.[rel.sourceTable]) {\n    throw new Error(`Source table '${rel.sourceTable}' 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(\"not found in datasource\")) {\n    await refreshDatasourceSchema(datasource)\n    // retry once with fresh entities\n  } else throw err\n}","preventionTips":["Sync/refresh the datasource schema before creating relationships.","Validate relationship table names against entities keys at config time.","Handle external renames/deletes by re-importing affected 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"}