Skip to content

Fix MikroORM Migration Up – Migration Not Applied

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Fix MikroORM Migration Up. We cover key concepts, practical examples, and best practices.

You run npx mikro-orm migration:up and the command says "No migrations to run" β€” even though you have a new migration file in the migrations directory. Or the migration fails with "ALTER TABLE ... column already exists".

Wrong ❌

npx mikro-orm migration:up

Output:

No migrations to run. Your database schema is up to date.

But there's a file `./migrations/Migration20240624000001.ts` that hasn't been applied. The migration directory is configured, but MikroORM doesn't see the pending migration.

## Right βœ…

```<a href="/programming-languages/typescript/">typescript</a>
// mikro-orm.config.ts
import { defineConfig } from '@mikro-orm/<a href="/databases/postgresql/">postgresql</a>';

export default defineConfig({
  entities: ['./dist/entities'],
  entitiesTs: ['./src/entities'],
  dbName: 'mydb',
  migrations: {
    path: './migrations',                        // directory for migration files
    pathTs: './migrations',                      // <a href="/programming-languages/typescript/">TypeScript</a> source
    glob: '!(*.d).{js,ts}',                      // pattern for migration files
    transactional: true,
    allOrNothing: true,
    emit: 'ts',                                  // generate as <a href="/programming-languages/typescript/">TypeScript</a>
    snapshot: true,
  },
});

```typescript
// migrations/Migration20240624000001.ts
import { Migration } from '@mikro-orm/migrations';

export class Migration20240624000001 extends Migration {
  async up(): Promise<void> {
    this.addSql('alter table "user" add column "phone" varchar(255) null;');
  }

  async down(): Promise<void> {
    this.addSql('alter table "user" drop column "phone";');
  }
}

```bash
# Check the migration status
npx mikro-orm migration:up --to 0   # (list all migrations)

# Output:
# Migration  20240624000001  pending

**Apply the pending migration:**

```bash
npx mikro-orm migration:up

Processing migration: Migration20240624000001
  βœ” up: alter table "user" add column "phone" varchar(255) null;
migration up finished (1 migrations)

**If "column already exists" β€” the database is out of sync:**

```bash
# Create a new migration from the entity changes
npx mikro-orm migration:create --blank
# Or generate a migration from schema diff:
npx mikro-orm schema:update --dump --run

**Check if the migration was already applied manually:**

```sql
SELECT * FROM mikrorm_migrations;
-- If the migration is listed, it was already applied.
-- Delete the row if you need to re-apply:
-- DELETE FROM mikrorm_migrations WHERE name = 'Migration20240624000001';

**Reset and re‑apply (development only):**

```bash
npx mikro-orm migration:fresh   # drops DB and re-applies all migrations

## Root Cause

MikroORM tracks applied migrations in the `mikrorm_migrations` table. If the migration file exists but isn't in the table, it should be applied. Common issues: the migration file is in the wrong directory, the `glob` pattern doesn't match, or the migration class name doesn't match the file name.

## Prevention

- Use `npx mikro-orm migration:create` to generate migrations β€” it creates the proper class structure.
- Always run `npx mikro-orm migration:up` after creating a new migration.
- Use `migrations.allOrNothing: true` to avoid partial migration.
- Check `mikrorm_migrations` table if migrations seem out of sync.


## Common Mistakes with migration up

1. **Using `head` and `tail` instead of pattern matching, causing runtime errors on empty lists**
2. **Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks**
3. **Using `return` to exit a function early instead of wrapping a pure value in the monad**

These mistakes appear frequently in real-world MIKROORM 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: How do I create a blank migration for manual SQL?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: <code>npx mikro-orm migration:create --blank</code>.</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 `migration:up` and `schema:update`?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: <code>migration:up</code> applies versioned migration files. <code>schema:update</code> syncs the schema directly from entities.</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 revert a migration?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes β€” <code>npx mikro-orm migration:down</code>.</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 generate a migration from entity changes?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: <code>npx mikro-orm migration:create</code> β€” it diffs entities vs the database and generates the SQL.</p>
</div></details>

---

*Migrations are covered in the [DodaTech MikroORM Data Management course](https://dodatech.com/courses/mikroorm).*

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro