{"record":{"id":"54067994107542a8","repo":"Budibase/budibase","slug":"self-referential-relationships-are-not-supported","errorCode":null,"errorMessage":"Self-referential relationships are not supported. Table ${table.name} cannot link to itself.","messagePattern":"Self-referential relationships are not supported\\. Table (.+?) cannot link to itself\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/helpers/table.ts","lineNumber":28,"sourceCode":"\nexport async function generateTables(\n  tables: { name: string; primaryDisplay: string; schema: TableSchema }[]\n) {\n  const createdTables: GenerateTablesResponse[\"createdTables\"] = []\n  const tableIds: Record<string, string> = {}\n\n  try {\n    for (const table of tables) {\n      for (const linkField of Object.values(table.schema).filter(\n        f => f.type === FieldType.LINK\n      )) {\n        if (!tables.find(t => t.name === linkField.tableId)) {\n          throw new Error(\n            `Table ${linkField.tableId} not found in the json response.`\n          )\n        }\n        if (linkField.tableId === table.name) {\n          throw new Error(\n            `Self-referential relationships are not supported. Table ${table.name} cannot link to itself.`\n          )\n        }\n      }\n    }\n\n    const existingTableNames = (await sdk.tables.getAllInternalTables()).map(\n      t => t.name\n    )\n\n    for (const table of tables) {\n      const name = helpers.getSequentialName(existingTableNames, table.name, {\n        separator: \" \",\n      })\n      const createdTable = await sdk.tables.create({\n        ...table,\n        name,\n        schema: {},","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/helpers/table.ts#L10-L46","documentation":"Error \"Self-referential relationships are not supported. Table ${table.name} cannot link to itself.\" thrown in Budibase/budibase.","triggerScenarios":"Thrown at packages/server/src/sdk/workspace/ai/helpers/table.ts:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}