Skip to content

Prisma is an open-source database toolkit that simplifies database workflows, making them more efficient and type-safe.

One of the common tasks during development is to reset your database and seed it with initial data, especially when you’re setting up the development environment or testing your application. In this post, we’ll walk you through how to do this with Prisma.

Resetting the Prisma database

When you want to revert your database to its initial state or apply new changes to the Prisma schema, you might need to reset it. Here’s how:

  1. Navigate to the root directory of your Prisma project.
  2. Run the following command to reset the database:
npx prisma migrate reset

This will:

  • Drop the database
  • Create a new database
  • Apply all migrations
  • Generate Prisma Client

Seeding the Prisma database

Seeding allows you to populate your database with predefined data. Here’s how to set up and run seeding with Prisma:

  1. Create a seed script

Create a new file named seed.ts (for TypeScript) or seed.js (for JavaScript) inside the prisma folder.

This file should export a function named seed that will handle the seeding logic. Here’s an example using TypeScript:

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function seed() {
    await prisma.user.create({
        data: {
            name: 'John Doe',
            email: '[email protected]',
        },
    });
}

seed()
  .catch((error) => {
    console.error(error);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
  1. Update Prisma schema

In your schema.prisma file, you’ll need to tell Prisma about your seed script. Modify the generator block to include a seed field:

generator client {
  provider = "prisma-client-js"
  seed    = "prisma/seed.ts" // or seed.js if you're using JavaScript
}
  1. Run the seed script

With everything in place, you can now seed your database with the following command:

npx prisma db seed

Prisma will execute the seed script, and your database will be populated with the data you’ve defined.

Validating the result

For Prisma workflows, Basedash works as an AI-native BI layer over your database so engineers and non-technical teammates can inspect migration outcomes, ask follow-up questions, and track changes in shared dashboards.

Conclusion

With Prisma’s streamlined CLI and the seeding setup, you can make sure your development environment is always in a consistent state. Remember to exercise caution when resetting databases, especially in production environments, to avoid any unintended data loss.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.