{"record":{"id":"bd2741166373cff1","repo":"payloadcms/payload","slug":"unique-is-not-supported-in-postgres-for-hasmany-nu","errorCode":null,"errorMessage":"Unique is not supported in Postgres for hasMany number fields.","messagePattern":"Unique is not supported in Postgres for hasMany number fields\\.","errorType":"http","errorClass":"InvalidConfiguration","httpStatus":500,"severity":"error","filePath":"packages/drizzle/src/schema/traverseFields.ts","lineNumber":743,"sourceCode":"      case 'number': {\n        if (field.hasMany) {\n          const isLocalized =\n            Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n            withinLocalizedArrayOrBlock ||\n            forceLocalized\n\n          if (isLocalized) {\n            hasLocalizedManyNumberField = true\n          }\n\n          if (field.index) {\n            hasManyNumberField = 'index'\n          } else if (!hasManyNumberField) {\n            hasManyNumberField = true\n          }\n\n          if (field.unique) {\n            throw new InvalidConfiguration(\n              'Unique is not supported in Postgres for hasMany number fields.',\n            )\n          }\n        } else {\n          targetTable[fieldName] = withDefault(\n            {\n              name: columnName,\n              type: 'numeric',\n            },\n            field,\n          )\n        }\n\n        break\n      }\n\n      case 'point': {\n        targetTable[fieldName] = withDefault(","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/drizzle/src/schema/traverseFields.ts#L725-L761","documentation":"Thrown during schema traversal (traverseFields.ts) when a number field that is hasMany (array of numbers) is declared with `unique: true`. A hasMany number field is stored in a separate rows table (one row per array element), and a SQL UNIQUE constraint across an array is not meaningful, so the Postgres adapter rejects it. The same field may use `index: true` instead.","triggerScenarios":"Defining a field `{ name: 'tags', type: 'number', hasMany: true, unique: true }` in a collection or global field config.","commonSituations":"Copy-pasting a single-value number field config and adding hasMany without removing unique; assuming 'unique array' is supported like in Mongo.","solutions":["Remove `unique: true` from the hasMany number field.","If you need per-element uniqueness, enforce it at the application layer or via a custom validation hook.","If only a single number must be unique, split into a separate non-hasMany number field with unique: true."],"exampleFix":"// before\n{ name: 'codes', type: 'number', hasMany: true, unique: true }\n// after\n{ name: 'codes', type: 'number', hasMany: true, index: true }","handlingStrategy":"validation","validationCode":"function assertNoUniqueOnHasManyNumber(fields) {\n  for (const f of fields) {\n    if (f.type === 'number' && f.hasMany && f.unique) {\n      throw new Error(`Field ${f.name}: unique is not allowed on hasMany number fields`)\n    }\n  }\n}","typeGuard":"const isHasManyNumber = (f) => f.type === 'number' && !!f.hasMany","tryCatchPattern":null,"preventionTips":["Never combine hasMany and unique on a number field.","Use a custom validate hook if you need array-member uniqueness."],"tags":["schema","unique","hasmany","number","postgres"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}