A Prisma schema needs a datasource, a generator, and your models before you can
migrate. This builder produces a valid schema.prisma stub with sensible
defaults — ids, timestamps, typed fields, and an optional one-to-many relation —
so you can go straight to prisma migrate dev.
How it works
Every schema starts with two blocks: a datasource naming the database provider
and pulling the connection string from env("DATABASE_URL"), and a generator
for the JavaScript client. Models follow, with field attributes like @id,
@default, and @unique:
model User {
id String @id @default(cuid())
email String @unique
name String?
createdAt DateTime @default(now())
posts Post[]
}
A one-to-many relation pairs a list field on the parent (posts Post[]) with a
foreign key and @relation annotation on the child, mapping the child’s
authorId to the parent’s id.
Tips and notes
Append ? to a field type to make it nullable. Keep the connection string in
.env as DATABASE_URL — never inline it. After copying the schema, run
npx prisma migrate dev --name init to create the tables and npx prisma generate to build the typed client. Switch the id default to
@default(autoincrement()) with an Int type if you prefer numeric primary
keys over cuids.