使用 Prisma Migrate
创建数据库模式
在本指南中,你将使用 Prisma 的 db push
命令在数据库中创建表。将以下 Prisma 数据模型添加到你的 Prisma 模式文件 prisma/schema.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
命令在数据库中创建了三个表 🚀