使用 Prisma Migrate
建立資料庫結構描述
在本指南中,您將使用 Prisma 的 db push
命令在您的資料庫中建立表格。將以下 Prisma 資料模型新增到 prisma/schema.prisma
中的 Prisma 結構描述。
prisma/schema.prisma
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @db.VarChar(255)
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
@@index(authorId)
}
model Profile {
id Int @id @default(autoincrement())
bio String?
user User @relation(fields: [userId], references: [id])
userId Int @unique
@@index(userId)
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
profile Profile?
}
您現在已準備好將新的結構描述推送至您的資料庫。使用連接您的資料庫中的指示連接到您的 main
分支。
現在使用 db push
CLI 命令推送至 main
分支
npx prisma db push
太棒了,您現在使用 Prisma 的 db push
命令在您的資料庫中建立了三個表格 🚀