Skip to content

Defining your data model

Course: Prisma - chapter 6

Prisma expects you to define the shape of your data in the schema.prisma file

Section titled “Prisma expects you to define the shape of your data in the schema.prisma file”

If your final app will have a Users table, it would look like this in the schema.prisma file

model User {
id Int @id @default(autoincrement())
username String @unique
password String
firstName String
lastName String
}

Add a Users and a Todo table in your application. Don’t worry about foreign keys / relationships just yet

Answer
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
username String @unique
password String
firstName String
lastName String
}
model Todo {
id Int @id @default(autoincrement())
title String
description String
done Boolean @default(false)
userId Int
}

You have created a single schema file. You haven’t yet run the CREATE TABLE commands. To run those and create migration files , run

npx prisma migrate dev --name Initialize the schema

Your DB should now have the updated schema.

💡 Check the prisma/migrations folder and check if you see anything interesting in there