{"record":{"id":"6dcecde255030029","repo":"Budibase/budibase","slug":"cannot-re-use-the-linked-column-name-for-a-linked","errorCode":null,"errorMessage":"Cannot re-use the linked column name for a linked table.","messagePattern":"Cannot re-use the linked column name for a linked table\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/db/linkedRows/LinkController.ts","lineNumber":110,"sourceCode":"  /**\n   * Makes sure the passed in table schema contains valid relationship structures.\n   */\n  validateTable(table: Table) {\n    const usedAlready = []\n    for (let schema of Object.values(table.schema)) {\n      if (schema.type !== FieldType.LINK) {\n        continue\n      }\n      if (\n        schema.fieldName &&\n        !schema.autocolumn &&\n        !schema.fieldName.match(ValidColumnNameRegex)\n      ) {\n        throw new Error(\"Column names can't contain special characters\")\n      }\n      const unique = schema.tableId! + schema?.fieldName\n      if (usedAlready.indexOf(unique) !== -1) {\n        throw new Error(\n          \"Cannot re-use the linked column name for a linked table.\"\n        )\n      }\n      usedAlready.push(unique)\n    }\n  }\n\n  /**\n   * Returns whether the two link schemas are equal (in the important parts, not a pure equality check)\n   */\n  areLinkSchemasEqual(linkSchema1: FieldSchema, linkSchema2: FieldSchema) {\n    const compareFields = [\n      \"name\",\n      \"type\",\n      \"tableId\",\n      \"fieldName\",\n      \"autocolumn\",\n      \"relationshipType\",","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/db/linkedRows/LinkController.ts#L92-L128","documentation":"`validateTable` tracks each link schema entry by `tableId + fieldName` in the `usedAlready` array while the table is saved. If two link columns resolve to the same unique key — the same fieldName used twice in one table, or the same fieldName on link columns pointing at the same table — the save is rejected to keep link document storage unambiguous.","triggerScenarios":"Defining two link columns with identical fieldName in a single table; a copy/paste or import creating duplicate link schema entries; API calls that PATCH the table schema appending a link column whose fieldName already exists on the same target table.","commonSituations":"Duplicating a table definition and accidentally duplicating link fields; CSV/table import tooling merging schemas; automation or plugin code updating the schema without checking for existing link field names.","solutions":["Rename one of the duplicate link columns so each fieldName is unique within the table.","Inspect table.schema via the API and remove redundant duplicate link entries before saving.","If the duplication comes from import code, deduplicate schema entries by fieldName before writing the table."],"exampleFix":"// before\nschema: { related_a: {type:\"link\", tableId: T}, related_a: {type:\"link\", tableId: T} }\n// after\nschema: { related_orders: {type:\"link\", tableId: T}, related_shipments: {type:\"link\", tableId: T} }","handlingStrategy":"validation","validationCode":"const seen = new Set<string>()\nfor (const [name, schema] of Object.entries(table.schema)) {\n  if (schema.type !== \"link\") continue\n  const key = schema.tableId + name\n  if (seen.has(key)) throw new Error(`Duplicate link column '${name}' for table ${schema.tableId}`)\n  seen.add(key)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.post(`/tables`, table)\n} catch (err) {\n  if (err.message.includes(\"re-use the linked column name\")) {\n    table.schema = dedupeLinkColumns(table.schema)\n    return api.post(`/tables`, table)\n  }\n  throw err\n}","preventionTips":["Uniquely name every link column within a table.","Deduplicate schema entries by fieldName before imports or PATCHes.","Review duplicated table definitions for cloned link fields."],"tags":["database","tables","linked-rows","duplicate-column"],"backgroundTag":"duplicate-link-column-name","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}