Next.js 14 How to set up Prisma with Mysql
Prisma is an open-source next-generation ORM. It consists of the following parts: Prisma Client: Auto-generated and type-safe query builder
https://www.prisma.io
Install prisma/client
npm install @prisma/client
https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client
Generate Prisma Client with the following command:
npx prisma generate
Install prisma
npm install prisma --save-dev
https://www.prisma.io/docs/getting-started/quickstart
set up Prisma with the init command of the Prisma CLI:
npx prisma init --datasource-provider sqlite
to npx prisma init --datasource-provider mysql
Model data in the Prisma schema
prisma/schema.prisma
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
Run a migration to create your database tables with Prisma Migrate
npx prisma migrate dev --name init
run C:\nextjs>npm run dev