{"record":{"id":"3f4d3b30accc23d4","repo":"Budibase/budibase","slug":"cannot-overwrite-existing-column","errorCode":null,"errorMessage":"Cannot overwrite existing column.","messagePattern":"Cannot overwrite existing column\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/db/linkedRows/LinkController.ts","lineNumber":398,"sourceCode":"        schema[fieldName] = fields.linkerField\n        const linkedField = fields.linkedField\n\n        if (field.autocolumn) {\n          linkedField.autocolumn = field.autocolumn\n          linkedField.subtype = field.subtype\n        }\n\n        if (field.aiGenerated) {\n          linkedField.aiGenerated = field.aiGenerated\n        }\n\n        // check the linked table to make sure we aren't overwriting an existing column\n        const existingSchema = linkedTable.schema[field.fieldName]\n        if (\n          existingSchema != null &&\n          !this.areLinkSchemasEqual(existingSchema, linkedField)\n        ) {\n          throw new Error(\"Cannot overwrite existing column.\")\n        }\n        // create the link field in the other table\n        linkedTable.schema[field.fieldName] = linkedField\n        const response = await this._db.put(linkedTable)\n        // special case for when linking back to self, make sure rev updated\n        if (linkedTable._id === table._id) {\n          table._rev = response.rev\n        }\n      }\n    }\n    return table\n  }\n\n  /**\n   * Update a table, this means if a field is removed need to handle removing from other table and removing\n   * any link docs that pertained to it.\n   * @returns The table which has been saved, same response as with the tableSaved function.\n   */","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/db/linkedRows/LinkController.ts#L380-L416","documentation":"When a table containing a link column is saved, tableSaved mirrors the link by writing a reciprocal link column named field.fieldName into the linked table. Before writing, it checks the linked table's existing schema: if a column with that name already exists and its definition is not equivalent to the link field that would be written, the save is aborted so an unrelated user column is not clobbered by the relationship metadata.","triggerScenarios":"Saving/updating a table (tableSaved via tableUpdated or updateLinks) where a link field's fieldName collides with an existing column of the same name in the target table, and the existing column is not an equal link schema.","commonSituations":"Naming the link column the same as a column that already exists on the other table (e.g. \"customer\" exists on both); renaming a link column to a taken name; linking a table to itself and reusing an existing field name; restoring a table definition from an export where the reciprocal column drifted.","solutions":["Rename the link column's fieldName (the name on the other table) to something not already present in the linked table's schema, then save again.","If the existing column is a leftover/stale link column, remove it from the linked table first and re-create the relationship.","If the schemas should match but don't, delete both link columns and re-create the relationship fresh so the reciprocal field is regenerated consistently.","Check for self-links: when field.tableId equals the table's own _id, ensure the reciprocal fieldName is unique within that one schema."],"exampleFix":"// before\n{ name: \"Orders\", type: \"link\", tableId: \"ta_customers\", fieldName: \"status\" } // collides with existing \"status\" column\n// after\n{ name: \"Orders\", type: \"link\", tableId: \"ta_customers\", fieldName: \"orders\" } // unique name on linked table","handlingStrategy":"validation","validationCode":"const linkedTable = await db.get(table.field.tableId)\nif (linkedTable.schema[table.field.fieldName] != null) {\n  throw new Error(`Column \"${table.field.fieldName}\" already exists on the linked table`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await saveTable(table)\n} catch (err) {\n  if (err.message === \"Cannot overwrite existing column.\") {\n    // prompt user to pick a different reciprocal column name\n  } else throw err\n}","preventionTips":["Check the target table's schema for name conflicts before creating a relationship","Use distinctive link column names (e.g. pluralized table names) on the reciprocal side","Clean up stale link columns on the linked table before re-creating relationships"],"tags":["database","schema","naming-collision","budibase"],"backgroundTag":"column-name-collision","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}