{"record":{"id":"fe26f70c2006fca1","repo":"payloadcms/payload","slug":"migration-migration-name-not-found-locally-fe26f7","errorCode":null,"errorMessage":"Migration ${migration.name} not found locally.","messagePattern":"Migration (.+?) not found locally\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/drizzle/src/migrateReset.ts","lineNumber":38,"sourceCode":"  const migrationFiles = await readMigrationFiles({ payload })\n\n  const { existingMigrations } = await getMigrations({ payload })\n\n  if (!existingMigrations?.length) {\n    payload.logger.info({ msg: 'No migrations to reset.' })\n    return\n  }\n\n  const req = await createLocalReq({}, payload)\n\n  existingMigrations.reverse()\n\n  // Rollback all migrations in order\n  for (const migration of existingMigrations) {\n    const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n    try {\n      if (!migrationFile) {\n        throw new Error(`Migration ${migration.name} not found locally.`)\n      }\n\n      const start = Date.now()\n      payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n      await initTransaction(req)\n      const db = await getTransaction(this, req)\n      await migrationFile.down({ db, payload, req })\n      payload.logger.info({\n        msg: `Migrated down:  ${migrationFile.name} (${Date.now() - start}ms)`,\n      })\n\n      const tableExists = await migrationTableExists(this, db)\n      if (tableExists) {\n        await payload.delete({\n          id: migration.id,\n          collection: 'payload-migrations',\n          req,\n        })","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/drizzle/src/migrateReset.ts#L20-L56","documentation":"Thrown by `migrateReset`, which rolls back every applied migration in reverse order to fully reset the database schema. Like the down/refresh variants, it requires that each row in `payload-migrations` has a corresponding local migration file exposing a `down()` function; if any name has no file, the reset cannot proceed.","triggerScenarios":"Calling `payload migrate:reset` (or the adapter's `migrateReset`) when the `payload-migrations` table contains a row whose migration file is absent from the migration directory read by `readMigrationFiles`.","commonSituations":"Resetting a long-lived DB whose older migration files were archived/deleted; branch switching that leaves orphaned DB rows; renamed migrations without a corresponding DB-row update; wrong `migrationDir`.","solutions":["Restore the missing migration file(s) from git so the local set matches the DB rows, then re-run reset.","On a disposable database, prefer `payload migrate:fresh` (drop+recreate) to avoid depending on every historical `down()`.","Delete orphaned rows in `payload-migrations` for files you intentionally removed, then retry reset.","Double-check the adapter's migration directory is the one that originally produced these migrations."],"exampleFix":"// before: payload migrate:reset fails on 'Migration 0003_indexes not found locally.'\n// after: restore file or wipe DB\n//   git checkout main -- src/migrations/0003_indexes.ts && payload migrate:reset\n// or for dev:  payload migrate:fresh","handlingStrategy":"validation","validationCode":"// Pre-check before reset\nconst files = await readMigrationFiles({ payload })\nconst { existingMigrations } = await getMigrations({ payload })\nconst known = new Set(files.map(f => f.name))\nif (existingMigrations.some(m => !known.has(m.name))) {\n  throw new Error('Aborting reset: some applied migrations lack local files')\n}\nawait payload.db.migrateReset()","typeGuard":"null","tryCatchPattern":"try {\n  await payload.db.migrateReset()\n} catch (err) {\n  if (/not found locally/.test(String(err?.message))) {\n    payload.logger.warn(`Reset blocked by drift; run migrate:fresh to recreate the DB.`)\n  }\n  throw err\n}","preventionTips":["Archive, don't delete, historical migration files.","Use migrate:fresh on disposable databases to avoid depending on old down() functions.","Keep the migrationDir stable across branches."],"tags":["migrations","drizzle","database-drift","reset"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}