Hey there! :wave: I’m seeing that the names of fo...
# orm-help
b
Hey there! 👋 I’m seeing that the names of foreign keys can conflict when a model has two relations with the same field. Here are the
schema.prisma
and the generated migration sql. It looks like foreign key names are in the format of
{tableName}_{field}_fkey
but I’m thinking we’d want the name to be something like
{sourceTable}_{sourceField}_{targetTable}_{targetField}_fkey
to handle this case. Any thoughts on this? Should I submit an issue to prisma-engines?
n
Hi Ben 👋 I tried the models from the schema and got the error as expected, you should ideally be getting this error as well: Error parsing attribute “@relation”: The given constraint name
memberships_member_id_fkey
has to be unique in the following namespace: on model
Membership
for primary key, indexes, unique constraints and foreign keys. Please provide a different name using the
map
argument. By providing map argument like this should solve the issue like this:
Copy code
model Membership {
  id          String @id
  memberId    String @map("member_id")
  memberType  String @map("member_type")
  memberUser  User?  @relation(fields: [memberId], references: [id], map: "member_user")
  memberGroup Group? @relation(fields: [memberId], references: [id])

  @@map("memberships")
}
Are you using latest version of prisma plugin in VS Code?
b
This worked great, Nurul! Thanks for the help 🙏 Our team uses Webstorm so we weren't seeing that error through the Prisma plugin 😢
🙌 1
n
That’s great to hear Ben! 🙌