{"record":{"id":"65916a8cfceac51a","repo":"payloadcms/payload","slug":"field-field-name-of-type-field-type-has","errorCode":null,"errorMessage":"Field \"${field.name}\" of type \"${field.type}\" has an empty relationTo array. At least one collection must be specified.","messagePattern":"Field \"(.+?)\" of type \"(.+?)\" has an empty relationTo array\\. At least one collection must be specified\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/payload/src/fields/config/sanitize.ts","lineNumber":254,"sourceCode":"  }\n\n  // Join field sanitization\n  if (field.type === 'join') {\n    sanitizeJoinField({\n      config,\n      field,\n      joinPath,\n      joins,\n      orderableJoins,\n      parentIsLocalized,\n      polymorphicJoins,\n    })\n  }\n\n  // Relationship/upload validation\n  if (field.type === 'relationship' || field.type === 'upload') {\n    if (Array.isArray(field.relationTo) && field.relationTo.length === 0) {\n      throw new Error(\n        `Field \"${field.name}\" of type \"${field.type}\" has an empty relationTo array. At least one collection must be specified.`,\n      )\n    }\n\n    if (validRelationships) {\n      const relationships = Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]\n\n      relationships.forEach((relationship: string) => {\n        if (!validRelationships.includes(relationship)) {\n          throw new InvalidFieldRelationship(field, relationship)\n        }\n      })\n    }\n  }\n\n  // Upload isSortable default\n  if (field.type === 'upload') {\n    if (!field.admin || !('isSortable' in field.admin)) {","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/fields/config/sanitize.ts#L236-L272","documentation":"A `relationship` or `upload` field has `relationTo` set to an empty array (`relationTo: []`). relationship/upload fields must point to at least one target collection slug; an empty array is meaningless and breaks schema generation and the admin select UI.","triggerScenarios":"`{ type: 'relationship', name: 'x', relationTo: [] }` or an upload field with empty relationTo; dynamically building `relationTo` from a filtered list that ends up empty.","commonSituations":"Computing `relationTo` from an env/config-driven list that resolves to nothing in some environment; partial refactor leaving `relationTo: []` as a placeholder; conditional spread that omits all entries.","solutions":["Provide at least one valid collection slug in `relationTo`.","If the field should not exist when the list is empty, conditionally omit the whole field from the fields array.","For upload fields, set `relationTo` to a single upload-enabled collection slug."],"exampleFix":"// before\n{ type: 'relationship', name: 'related', relationTo: [] }\n// after\n{ type: 'relationship', name: 'related', relationTo: ['posts'] }","handlingStrategy":"validation","validationCode":"function findEmptyRelationTo(fields) {\n  const bad = []\n  for (const f of fields) {\n    if ((f?.type === 'relationship' || f?.type === 'upload') && Array.isArray(f?.relationTo) && f.relationTo.length === 0) {\n      bad.push(f.name)\n    }\n    if (Array.isArray(f?.fields)) bad.push(...findEmptyRelationTo(f.fields))\n  }\n  return bad\n}","typeGuard":"function relationToIsNonEmpty(f: any): boolean {\n  if (f?.type !== 'relationship' && f?.type !== 'upload') return true\n  if (Array.isArray(f.relationTo)) return f.relationTo.length > 0\n  return typeof f.relationTo === 'string' && f.relationTo.length > 0\n}","tryCatchPattern":"try {\n  await payload.init({ config })\n} catch (err) {\n  if (/empty relationTo/i.test(err?.message ?? '')) console.error('relationship/upload field with empty relationTo')\n  throw err\n}","preventionTips":["When building `relationTo` dynamically, fall back to a default or skip the field entirely if the list is empty.","Add a CI check that scans for `relationTo: []` in config files."],"tags":["relationship","upload","config","schema","sanitization"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}