使用 Prisma Migrate
创建数据库 schema
在本指南中,你将使用 Prisma 的 db push
命令 来在你的数据库中创建表。将以下 Prisma 数据模型添加到你的 Prisma schema 中的 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?
}
你现在可以准备好将你的新 schema 推送到你的数据库了。使用 连接你的数据库 中的说明连接到你的 main
分支。
现在使用 db push
CLI 命令推送到 main
分支
npx prisma db push
太棒了,你现在使用 Prisma 的 db push
命令在你的数据库中创建了三个表 🚀