Creating a Migration for Mikro-Orm

2.4k Views Asked by At

I'm currently trying to a create a new migration in my project after the initial one. I started with a script and although it's running throughout with no errors, the actual job didn't go through.

yarn mikro-orm migration:create

I decided to turn my script off and use the above CLI to get it working, and it still hasn't created but has continuously given my an output of...

No changes required, schema is up-to-date

I've already ran through an update on my schema to check if anything was wrong but there were no errors.

3

There are 3 best solutions below

1
On BEST ANSWER

What happens when you run migration:up?

I recommend experimenting with these commands:

npx mikro-orm migration:up       # Migrate up to the latest version
npx mikro-orm migration:down     # Migrate one step down
npx mikro-orm migration:list     # List all executed migrations
npx mikro-orm migration:pending  # List all pending migrations
0
On

I was able to solve this issue by removing the .snapshot-test-migration.json under the migrations folder.

0
On

I have been struggled for a while before I can come up with this.

  1. If you are working on Typescript, check if your mikro-orm config look up entities in JS or TS. I have tried several times for having updated the TS files, forgetting to build the JS files but run mikro-orm migration:create directly. It makes the CLI checking on the unchanged JS files and response 'no changes' required.

  2. Besides of above, I also find clearing the mikro-orm cache, and generate new cache helps me to ensure I am in a freshly-new state.

In summary, my not-so-smart steps are:

yarn build // or the build command of your project
npx mikro-orm cache:clear // clear all cache
npx mikro-orm cache:generate // re-generate JS cache...
npx mikro-orm cache:generate --ts // ...or re-generate TS cache
npx mikro-orm migration:create