{"id":"b8c3467e93ab937f","repo":"prisma/prisma","slug":"psl-invalid-relation-attribute","errorCode":"PSL_INVALID_RELATION_ATTRIBUTE","errorMessage":"Backrelation list field \"${model.name}.${field.name}\" cannot declare fields/references; define them on the FK-side relation field","messagePattern":"Backrelation list field \"(.+?)\\.(.+?)\" cannot declare fields/references; define them on the FK-side relation field","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/2-sql/2-authoring/contract-psl/src/interpreter.ts","lineNumber":781,"sourceCode":"      familyId: input.familyId,\n      targetId: input.targetId,\n    });\n    let relationName: string | undefined;\n    if (relationAttribute) {\n      const parsedRelation = interpretRelationAttribute({\n        selfModel: model,\n        field,\n        symbols: input.symbolTable,\n        sourceFile: input.sourceFile,\n        sourceId,\n        diagnostics,\n      });\n      if (!parsedRelation) {\n        continue;\n      }\n      if (parsedRelation.fields || parsedRelation.references) {\n        diagnostics.push({\n          code: 'PSL_INVALID_RELATION_ATTRIBUTE',\n          message: `Backrelation list field \"${model.name}.${field.name}\" cannot declare fields/references; define them on the FK-side relation field`,\n          sourceId,\n          span: relationAttribute.span,\n        });\n        continue;\n      }\n      if (\n        parsedRelation.onDelete ||\n        parsedRelation.onUpdate ||\n        parsedRelation.index !== undefined\n      ) {\n        diagnostics.push({\n          code: 'PSL_INVALID_RELATION_ATTRIBUTE',\n          message: `Backrelation list field \"${model.name}.${field.name}\" cannot declare onDelete/onUpdate/index; define them on the FK-side relation field`,\n          sourceId,\n          span: relationAttribute.span,\n        });\n        continue;","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/prisma/prisma/blob/1243cdffbec0506c595ac8fd5865fe258c336fa0/packages/2-sql/2-authoring/contract-psl/src/interpreter.ts#L763-L799","documentation":"Emitted while scanning backrelation (list-side) fields in `buildModelNodeFromPsl`. The non-owning side of a Prisma relation — the list field — must not declare `fields`/`references`; those belong exclusively on the FK-side (owning) relation field so the foreign key is built in exactly one place. When `interpretRelationAttribute` returns `fields` or `references` on a list/backrelation field, this diagnostic is pushed with the relation attribute's span and the field is skipped.","triggerScenarios":"Writing `model Post { comments Comment[] @relation(fields: [id]) }` on the list side. The loop detects the backrelation candidate, parses the `@relation` attribute, and finds `parsedRelation.fields || parsedRelation.references` present, which is invalid for the non-owning side.","commonSituations":"Copy-pasting the owning side's `@relation(fields: [...], references: [...])` onto the opposite list field; misunderstanding which side owns the foreign key; auto-formatting/importing from a Prisma schema that annotated both sides.","solutions":["Remove `fields:`/`references:` from the list field's `@relation`.","Ensure the FK-side (the scalar/owning) field on the related model declares `@relation(fields: [...], references: [...])`."],"exampleFix":"// before\nmodel Post {\n  id Int @id\n  comments Comment[] @relation(fields: [id], references: [postId])\n}\nmodel Comment {\n  postId Int\n  post Post @relation(fields: [postId], references: [id])\n}\n\n// after\nmodel Post {\n  id Int @id\n  comments Comment[]\n}\nmodel Comment {\n  postId Int\n  post Post @relation(fields: [postId], references: [id])\n}","handlingStrategy":"validation","validationCode":"function findBackrelationWithFieldsOrReferences(psl) {\n  const issues = [];\n  for (const blk of psl.matchAll(/^model\\s+(\\w+)\\s*\\{([^}]*)\\}/gms)) {\n    const modelName = blk[1];\n    for (const f of blk[2].matchAll(/(\\w+)\\s+[A-Za-z_]\\w*\\[\\]\\s+@relation\\(([^)]*)\\)/g)) {\n      if (/fields\\s*:/.test(f[2]) || /references\\s*:/.test(f[2]))\n        issues.push({ model: modelName, field: f[1] });\n    }\n  }\n  return issues;\n}","typeGuard":"import type { ContractSourceDiagnostic } from \"@prisma-next/config/config-types\";\nexport function isBackrelationFieldsReferencesDiagnostic(d: ContractSourceDiagnostic): d is ContractSourceDiagnostic & { code: 'PSL_INVALID_RELATION_ATTRIBUTE' } {\n  return d.code === 'PSL_INVALID_RELATION_ATTRIBUTE' && d.message.includes('cannot declare fields/references');\n}","tryCatchPattern":null,"preventionTips":["On the list (back-relation) side, never set fields/references; those live on the FK-owning field.","Remember a list-typed relation field is the many side and cannot own the foreign-key mapping.","Put fields/references only on the single-valued relation field that owns the column."],"tags":["psl","schema","relation","backrelation","foreign-key"],"analyzedSha":"1243cdffbec0506c595ac8fd5865fe258c336fa0","analyzedAt":"2026-08-01T19:42:02.087Z","schemaVersion":2}