Fix Prisma Seed Not Working – Seed Script Fails or Doesn't Run
DodaTech
Updated 2026-06-24
3 min read
In this tutorial, you'll learn about Fix Prisma Seed Not Working. We cover key concepts, practical examples, and best practices.
You run npx prisma db seed and get "Error: Seed script is not configured" — or the script runs without errors but the database has no data.
Wrong ❌
// prisma/seed.js
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
// ❌ No main() wrapper, error handling, or disconnect
await prisma.user.create({ data: { email: 'test@test.com' } });
// SyntaxError: await is only valid in async function
```bash
npx prisma db seed
Error:
Error: Command "node prisma/seed.js" failed with exit code 1
The seed file uses `await` at the top level without an async wrapper.
## Right ✅
```prisma
// schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ... models
// 🔽 Add the seed configuration:
// prisma:
// seed: ts-node --compiler-options '{"module":"CommonJS"}' prisma/seed.ts
```json
// package.json
{
"prisma": {
"seed": "node prisma/seed.js"
}
}
```javascript
// prisma/seed.js
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function main() {
console.log('Seeding...');
const user = await prisma.user.create({
data: {
email: 'alice@example.com',
name: 'Alice',
posts: {
create: [
{ title: 'First post', content: 'Hello world' },
],
},
},
});
console.log('Created user:', user.id);
const users = await prisma.user.createMany({
data: [
{ email: 'bob"@example".com', name: 'Bob' },
{ email: 'carol"@example".com', name: 'Carol' },
],
skipDuplicates: true,
});
console.log(`Created ${users.count} users`);
}
main()
.catch((e) => {
console.error('Seed failed:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
**Run the seed:**
```bash
npx prisma db seed
# Seeding...
# Created user: 1
# Created 2 users
# 🌱 The seed command has been executed.
**For <a href="/programming-languages/typescript/">TypeScript</a> seed files:**
```json
{
"prisma": {
"seed": "ts-node prisma/seed.ts"
}
}
**Seed on every migration:**
```bash
npx prisma migrate dev --name add_roles
# Automatically runs seed after migration
**If seed runs but no data appears:**
Check that `prisma db seed` targets the right database:
```bash
# Confirm DATABASE_URL in .env
cat .env | grep DATABASE_URL
# Check the database directly
psql -d mydb -c "SELECT count(*) FROM users;"
## Root Cause
Prisma seed requires: (1) the `prisma.seed` field in `package.json`; (2) a valid script path; (3) proper async handling; (4) `prisma.$disconnect()` after completion. Missing any of these causes silent or explicit failure.
## Prevention
- Configure `prisma.seed` in `package.json` immediately after setting up Prisma.
- Use `createMany` with `skipDuplicates: true` for idempotent seeds.
- Add `process.exit(1)` in the catch block so CI fails on seed errors.
- Run `prisma db seed` after `migrate reset` to verify the seed works.
## Common Mistakes with seed not working
1. **Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks**
2. **Using `return` to exit a function early instead of wrapping a pure value in the monad**
3. **Mixing let bindings with <- bindings in do notation, producing type errors**
These mistakes appear frequently in real-world PRISMA code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
## Practice Exercise
**Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.**
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
## FAQ
<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I use a different seed per environment?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: No — Prisma supports only one seed configuration. Use environment variables in the script to branch.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: How do I reset and seed in one command?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: <code>prisma migrate reset</code> resets the DB and runs the seed automatically.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: What's the difference between `createMany` and `create`?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: <code>createMany</code> inserts multiple rows in a single query (faster). <code>create</code> supports nested creates (relations).</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I seed with production data?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes — but use <code>skipDuplicates: true</code> and wrap in a transaction for idempotency.</p>
</div></details>
---
*Database seeding is covered in the [DodaTech Prisma Data Seeding course](https://dodatech.com/courses/prisma).*
← Previous
Fix Prisma Migrate Error – Migration Fails to Apply
Next →
Pro Tools Bounce to Disk Not Working or Wrong Format Fix
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro