I am using prisma with three models,
model User {
id String @id @default(cuid())
name String @unique @db.VarChar(35)
email String @unique @db.VarChar(512)
password String @db.VarChar(1024)
details String @default("") @db.VarChar(512)
avatar String @default("/default-avatar.svg") @db.VarChar(150)
activity String @default("Online") @db.VarChar(25)
likes Int @default(0)
suggestions Boolean @default(false)
verified Boolean @default(false)
blockedUsers BlockedUser[]
comments Comment[]
communities Community[]
communityMembers CommunityMember[]
followers Follower[]
friends Friend[]
messages Message[]
posts Post[]
openDMs DM[]
interests UserInterest[]
@@map("user")
}
model Community {
id String @id @default(cuid())
title String @unique @db.VarChar(35)
details String @db.VarChar(512)
memberID String?
membersUser User[]
members CommunityMember[]
interests CommunityInterest[]
posts Post[]
@@map("community")
}
model CommunityMember {
id String @id @default(cuid())
nickname String?
userID String
communityID String
user User @relation(fields: [userID], references: [id])
community Community @relation(fields: [communityID], references: [id])
owner Boolean
@@map("community_member")
}
I have a route in my backend that causes the problem. It creates a new community member table with prisma client and connects the existing user and community to itself, with their ids.
When I do this, I get an error: Unique constraint failed on the constraint: community_member_communityID_key
Here is the code with the creation of the community member:
await prisma.communityMember.create({
data: {
nickname: response.account.name,
user: {
connect: { id: response.account.id }
},
community: {
connect: { id: communityID }
},
owner: false
}
});
I have tried dropping the database and resetting the prisma migrations, with no luck.
When I view the table in mysql, it is apparent that the communityID and userID fields are set as unique, so I think this problem has to do with prisma migrate.
Does anybody know what's happening, and how I can successfully create these fields without them being unique?