clean _prisma_migrations
haroldgrondel
HOBBYOP

a month ago

how can I clean _prisma_migrations?

$10 Bounty

5 Replies

Railway
BOT

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


abhishek72-avail
HOBBY

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

  1. 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--

  1. Connect to your database, then run:

DELETE FROM "_prisma_migrations";

Then re-baseline so Prisma knows your schema is already applied:

bash

  1. 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

  1. 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

  1. 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--

  1. Drop the table completely

DROP TABLE "_prisma_migrations";

bash

  1. Prisma will recreate it automatically on next migrate command

npx prisma migrate deploy


haroldgrondel
HOBBYOP

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)

  1. ✓ Fixed migration SQL (DATETIME → TIMESTAMP, DECIMAL → DECIMAL(65,30))
  2. ✓ Created brand new PostgreSQL database (hayabusa service)
  3. ✓ Updated DATABASE_URL environment variable to point to new DB
  4. ✓ Implemented npx prisma migrate reset --force script
  5. ✓ Removed all problematic code (tariff migrations, truncate scripts)
  6. ✓ 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:

  1. Diagnosing why pre-deploy command consistently fails
  2. Whether infrastructure reset/rebuild is needed
  3. 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


phuntjr17-crypto
FREE

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.


haroldgrondel
HOBBYOP

a month ago

Thanks all, we replayed the migrations one by one and it came out clean!


Welcome!

Sign in to your Railway account to join the conversation.

Loading...