mel
02/09/2022, 7:34 PMmodel User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
request Request?
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @updatedAt @db.Timestamptz(6)
}
model Request {
id Int @id @default(autoincrement())
user User @relation(fields: [id], references: [id])
// I also tried making the relation field userId
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @updatedAt @db.Timestamptz(6)
}
When I try to migrate this, I get an error that says:
failed to apply cleanly to the shadow database. Error: db error: ERROR: foreign key constraint “Request_userId_fkey” cannot be implemented DETAIL: Key columns “userId” and “id” are of incompatible types: text and uuid.The prisma documents dont show an example using uuid. The example they do give has a second parameter in the Profile model which has a userId as an Int. I tried adding this to my Request model (as an int, as a string and as a uuid). None of these worked.
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
role Role @default(USER)
posts Post[]
profile Profile?
}
model Profile {
id Int @id @default(autoincrement())
bio String
user User @relation(fields: [userId], references: [id])
userId Int
}
How can I reference a userId when it is generated using uuid? thank youAustin Zentz
02/09/2022, 7:40 PMuserId String @db.Uuid
user User @relation(fields: [profileId], references: [id])