a month ago
how can I clean _prisma_migrations?
5 Replies
a month ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • about 1 month ago
a month ago
Scenario A: You just want to wipe all migration history and start fresh (dev/local DB)
This is the safest full-reset method — Prisma handles dropping and recreating the table for you.
bash
- This drops the database, recreates it, re-runs all migrations, and reseeds
npx prisma migrate reset
That's it — one command. It will prompt for confirmation (add --force to skip the prompt in scripts):
bash
npx prisma migrate reset --force
⚠️ This deletes all data in the database, not just migration history. Only use on dev/test databases.
Scenario B: You want to manually empty just the _prisma_migrations table (keep your actual data)
Use this if your real tables/data should stay intact, and you only want to clear migration tracking.
sql--
- Connect to your database, then run:
DELETE FROM "_prisma_migrations";
Then re-baseline so Prisma knows your schema is already applied:
bash
- For each existing migration folder, mark it as applied
npx prisma migrate resolve --applied "20240101120000_init"
repeat for every migration folder name in prisma/migrations/
Scenario C: A migration is stuck as "failed" and blocking new migrations
This is the most common reason people want to "clean" this table.
bash
- Check migration status first
npx prisma migrate status
bash
2a. If the migration WAS actually applied successfully to the DB, mark it resolved:
npx prisma migrate resolve --applied "<migration_name>"
2b. If the migration was NOT applied (failed halfway), mark it rolled back:
npx prisma migrate resolve --rolled-back "<migration_name>"
bash
- Then continue normally
npx prisma migrate deploy
Scenario D: Drop the table entirely and let Prisma recreate it
Only do this if the table itself is corrupted.
sql--
- Drop the table completely
DROP TABLE "_prisma_migrations";
bash
- Prisma will recreate it automatically on next migrate command
npx prisma migrate deploy
a month ago
More info :
Service: immo-app (Node.js/Next.js)
Status: FAILED (pre-deploy command)
Problem
Every deployment fails at the pre-deploy stage, regardless of code changes or strategy:
- Initialization: ✓ Success (00:13)
- Build: ✓ Success (00:13)
- Deploy > Pre-deploy command: ✗ Failed (00:15)
- Error: "Pre-deploy command failed"
What We've Tried (30+ Attempts)
- ✓ Fixed migration SQL (DATETIME → TIMESTAMP, DECIMAL → DECIMAL(65,30))
- ✓ Created brand new PostgreSQL database (hayabusa service)
- ✓ Updated DATABASE_URL environment variable to point to new DB
- ✓ Implemented
npx prisma migrate reset --forcescript - ✓ Removed all problematic code (tariff migrations, truncate scripts)
- ✓ Code builds successfully locally with
npm run build
Current State
- Local code: ✓ Builds, runs, all phases 1-4 operational
- Database: ✓ Fresh, clean, zero migration history
- Configuration: ✓ DATABASE_URL correctly set to new DB
Suspected Root Cause
The failure is NOT in application code (verified locally). Suspect:
- Pre-deploy command pipeline configuration issue in Railway infrastructure
- Connectivity problem between container and database
- Build cache or internal Railway state issue
Please advise on:
- Diagnosing why pre-deploy command consistently fails
- Whether infrastructure reset/rebuild is needed
- Any known issues with Prisma migrate on fresh databases
a month ago
If you want to rebuild without build cache, you can try add NO_CACHE=1 to your environment variables
a month ago
Check your pre-deploy command to ensure it's set to 'npx prisma migrate deploy', and try adding the NO_CACHE=1 environment variable to force a fresh build.
a month ago
Thanks all, we replayed the migrations one by one and it came out clean!
