将 Prisma Migrate 与 TypeScript 和 PlanetScale 结合使用
创建数据库架构
¥Creating the database schema
在本指南中,你将使用 Prisma 的 db push
命令 在数据库中创建表。将以下 Prisma 数据模型添加到 prisma/schema.prisma
中的 Prisma 架构中:
¥In this guide, you'll use Prisma's db push
command to create the tables in your database. Add the following Prisma data model to your Prisma schema in 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
分支。
¥You are now ready to push your new schema to your database. Connect to your main
branch using the instructions in Connect your database.
现在使用 db push
CLI 命令推送到 main
分支:
¥Now use the db push
CLI command to push to the main
branch:
npx prisma db push
太好了,你现在使用 Prisma 的 db push
命令在数据库中创建了三个表 🚀
¥Great, you now created three tables in your database with Prisma's db push
command 🚀