{"record":{"id":"81cb589f2e17145e","repo":"Budibase/budibase","slug":"column-oldcolumn-name-is-a-one-to-many-column","errorCode":null,"errorMessage":"Column \"${oldColumn.name}\" is a one-to-many column but \"${newColumn.name}\" is not a single user column","messagePattern":"Column \"(.+?)\" is a one-to-many column but \"(.+?)\" is not a single user column","errorType":"validation","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/tables/migration.ts","lineNumber":138,"sourceCode":"  if (newColumn.subtype !== BBReferenceFieldSubType.USER) {\n    throw new BadRequestError(`Column \"${newColumn.name}\" is not a user column`)\n  }\n\n  if (!isRelationshipField(oldColumn)) {\n    throw new BadRequestError(\n      `Column \"${oldColumn.name}\" is not a user relationship`\n    )\n  }\n\n  if (oldColumn.tableId !== InternalTable.USER_METADATA) {\n    throw new BadRequestError(\n      `Column \"${oldColumn.name}\" is not a user relationship`\n    )\n  }\n\n  if (oldColumn.relationshipType === RelationshipType.ONE_TO_MANY) {\n    if (newColumn.type !== FieldType.BB_REFERENCE_SINGLE) {\n      throw new BadRequestError(\n        `Column \"${oldColumn.name}\" is a one-to-many column but \"${newColumn.name}\" is not a single user column`\n      )\n    }\n    return new SingleUserColumnMigrator(table, oldColumn, newColumn)\n  }\n  if (\n    oldColumn.relationshipType === RelationshipType.MANY_TO_MANY ||\n    oldColumn.relationshipType === RelationshipType.MANY_TO_ONE\n  ) {\n    if (newColumn.type !== FieldType.BB_REFERENCE) {\n      throw new BadRequestError(\n        `Column \"${oldColumn.name}\" is a ${oldColumn.relationshipType} column but \"${newColumn.name}\" is not a multi user column`\n      )\n    }\n\n    return new MultiUserColumnMigrator(table, oldColumn, newColumn)\n  }\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/tables/migration.ts#L120-L156","documentation":"The target column type must match the cardinality of the old relationship. A ONE_TO_MANY relationship can only be migrated to a single user column (BB_REFERENCE_SINGLE). getColumnMigrator throws this BadRequestError when a one-to-many relationship is paired with a multi-user BB_REFERENCE target.","triggerScenarios":"Invoking the migrator with oldColumn.relationshipType === RelationshipType.ONE_TO_MANY and newColumn.type === FieldType.BB_REFERENCE (multi) instead of BB_REFERENCE_SINGLE.","commonSituations":"Constructing migration payloads in bulk with a fixed target type without inspecting each relationship's cardinality.","solutions":["Use FieldType.BB_REFERENCE_SINGLE as the target for ONE_TO_MANY relationships","Derive the target type from cardinality: ONE_TO_MANY -> BB_REFERENCE_SINGLE, otherwise BB_REFERENCE","Use migrate() (not getColumnMigrator) which picks the correct type automatically"],"exampleFix":"// before\nconst newColumn = { name: \"owner\", type: FieldType.BB_REFERENCE, subtype: BBReferenceFieldSubType.USER }\n// after\nconst newColumn = { name: \"owner\", type: FieldType.BB_REFERENCE_SINGLE, subtype: BBReferenceFieldSubType.USER }","handlingStrategy":"validation","validationCode":"if (oldColumn.relationshipType === RelationshipType.ONE_TO_MANY &&\n    newColumn.type !== FieldType.BB_REFERENCE_SINGLE) {\n  throw new Error(\"ONE_TO_MANY must migrate to a single user column\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map relationshipType to target type: ONE_TO_MANY -> BB_REFERENCE_SINGLE","Let migrate() derive the target type from cardinality automatically"],"tags":["bad-request","schema","cardinality","migration"],"backgroundTag":"invalid-field-type","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}