ค้นหาเว็บไซต์

typescript - การย้ายฐานข้อมูล Prisma ต้องการค่าดีฟอลต์หรือไม่?


ฉันกำลังมีปัญหาเกี่ยวกับการสร้างโมเดลข้อมูล Prisma ฉันได้ลองเกือบทุกอย่างแล้วแต่ยังไม่เข้าใจว่าข้อผิดพลาดนี้เกิดขึ้นเพราะอะไร มันบอกว่าตารางต้องการค่าดีฟอลต์ทั้งที่ฉันได้ให้ ID แล้ว จากนั้นฉันก็ลองลบชื่อความสัมพันธ์ แต่สิ่งเดียวกันก็เกิดขึ้น นี่คือโมเดลของฉัน:

model UserToUser {
id          Int   @id @default(autoincrement())
userId      Int?
follower    User? @relation("follower",fields: [userId], references: [id])
following   User  @relation("following", fields: [followingId], references: [id])
followingId Int  
}

จากนั้นมันให้ข้อผิดพลาดมาว่า "ขั้นตอนที่ 2 เพิ่มคอลัมน์ที่จำเป็น followingId ไปยังตาราง UserToUser โดยไม่มีค่าดีฟอลต์ มี 2 แถวในตารางนี้ ไม่สามารถดำเนินการขั้นตอนนี้ได้" ฉันจะแก้ไขมันอย่างไร?

model User {
id              Int               @id @default(autoincrement())
points          Int               @default(0)
email           String            @unique
password        String
name            String?
posts           Post[]
Profile         Profile?
About           About?
Update          Update[]
Liked           Liked[]
following       UserToUser[] @relation("following")
follower        UserToUser[] @relation("follower")
}

คำตอบ #1

คุณสามารถเห็นตัวอย่างนี้จากเอกสาร Prisma ได้หรือไม่?

model User {
  id          Int      @id @default(autoincrement())
  name        String?
  followedBy  User[]   @relation("UserFollows", references: [id])
  following   User[]   @relation("UserFollows", references: [id])
}