prisma foreign key constraint error after merging user & admin into 1 table

I was handling authorization like this that i make a model for users and model for admin and each one has an email and password but now i am trying to refactor my code by merging users and admin into 1 table and handle auths like below model all_users { id String @id @default(uuid()) name String email String @unique(map: "user_email_key") password String role String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt user user? admin admin? } model user{ id String? alluserId String? @unique user all_users ? @relation(fields: [userId], references: [id]) votes votes[] } model admin{ id String? alluserId String? @unique user all_users ? @relation(fields: [userId], references: [id]) votes votes[] } model votes{ id String @id @default(uuid()) votes Json? user user @relation(fields: [userId], references: [alluserId]) userId String admin admin @relation(fields: [adminId], references: [alluserId]) adminId String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([entrepreneurId], name: "index_votes") } but now when I try to make npx prisma db push so I can use votes i always get this error insert or update on table "votes" violates foreign key constraint "votes_userId_fkey" 0: sql_schema_connector::apply_migration::migration_step I am not sure why this happens , therefor prisma has no errors.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server