{"record":{"id":"0aea4a1e3d313255","repo":"payloadcms/payload","slug":"unique-is-not-supported-in-postgres-for-hasmany-te","errorCode":null,"errorMessage":"Unique is not supported in Postgres for hasMany text fields.","messagePattern":"Unique is not supported in Postgres for hasMany text fields\\.","errorType":"http","errorClass":"InvalidConfiguration","httpStatus":500,"severity":"error","filePath":"packages/drizzle/src/schema/traverseFields.ts","lineNumber":1013,"sourceCode":"      case 'text': {\n        if (field.hasMany) {\n          const isLocalized =\n            Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n            withinLocalizedArrayOrBlock ||\n            forceLocalized\n\n          if (isLocalized) {\n            hasLocalizedManyTextField = true\n          }\n\n          if (field.index) {\n            hasManyTextField = 'index'\n          } else if (!hasManyTextField) {\n            hasManyTextField = true\n          }\n\n          if (field.unique) {\n            throw new InvalidConfiguration(\n              'Unique is not supported in Postgres for hasMany text fields.',\n            )\n          }\n        } else {\n          targetTable[fieldName] = withDefault(\n            {\n              name: columnName,\n              type: 'varchar',\n            },\n            field,\n          )\n        }\n        break\n      }\n\n      default:\n        break\n    }","sourceCodeStart":995,"sourceCodeEnd":1031,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/drizzle/src/schema/traverseFields.ts#L995-L1031","documentation":"Thrown during schema traversal when a text field that is hasMany is declared with `unique: true`. Like the number case, a hasMany text field is materialized as multiple rows in a separate table, so a UNIQUE constraint is not applicable; the adapter rejects the config at build time. `index: true` is allowed.","triggerScenarios":"Defining `{ name: 'tags', type: 'text', hasMany: true, unique: true }`.","commonSituations":"Treating a hasMany text field like a set and expecting DB-level uniqueness enforcement; migrating a Mongo schema where unique arrays were tolerated.","solutions":["Remove `unique: true` from the hasMany text field.","Enforce uniqueness of array members with a custom validate hook on the field.","Use `index: true` if you need lookup performance without uniqueness."],"exampleFix":"// before\n{ name: 'tags', type: 'text', hasMany: true, unique: true }\n// after\n{ name: 'tags', type: 'text', hasMany: true, index: true }","handlingStrategy":"validation","validationCode":"function assertNoUniqueOnHasManyText(fields) {\n  for (const f of fields) {\n    if (f.type === 'text' && f.hasMany && f.unique) {\n      throw new Error(`Field ${f.name}: unique is not allowed on hasMany text fields`)\n    }\n  }\n}","typeGuard":"const isHasManyText = (f) => f.type === 'text' && !!f.hasMany","tryCatchPattern":null,"preventionTips":["Never combine hasMany and unique on a text field.","Enforce tag uniqueness in a beforeChange hook instead."],"tags":["schema","unique","hasmany","text","postgres"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}