Setup a database model in Blitzjs

InstructorKhaled Garbaya

Share this video with your friends

Send Tweet

By default, Blitz uses Prisma 2 which is a strongly typed database client.

Prisma 2 is not required for Blitz. You can use anything you want, such as Mongo, TypeORM, etc.

To add a Database Table you need to add a model to your db/shcema.prisma file.


model Post {
  id   Int  @default(autoincrement()) @id
  slug String @unique
  title String
  content String

Then run blitz db migrate. the cli will prompt you to name the migration, give it any name you want, and confirm.

After the migration is done you can explore your DB tables using blitz db studio.

For local development using sqlite is very convenient as it is basically a file and it does not require any extra setup.