3

When trying to run the TypeORM Migrations, either automatically in the application startup or manually via the TypeORM CLI, only the migrations table gets created (and it stays empty). The migration files themselves are not being executed.

Here is my tsconfig.json

{ "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "target": "es2017", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", "incremental": true } } 

Here is my package.json

... "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js", ... 

Here is my ormconfig.json

... "entities": ["dist/**/*.entity{.ts,.js}"], "synchronize": true, "migrationsRun": true, "migrations ": ["dist/migrations/*{.ts,.js}"], "cli": { "migrationsDir": "src/migrations" } ... 

The migration files are being created through the TypeORM CLI and they are to populate some tables (insert statements). They are not related to changes in the database schema.

Please, can anyone help me make it work?

2
  • run this command npx typeorm migration:run Commented Aug 25, 2020 at 18:24
  • I tried it but the only thing that happens is that the migrations table gets created (if it's not yet created). It's as if the migration files I created with the insert statements are not being found. I checked "migrations": ["dist/migrations/*{.ts,.js}"]and the files (.ts and .js) are all there. Commented Aug 25, 2020 at 18:42

3 Answers 3

3

That was a silly one! I guess some times the simplest problems are the hardest to spot.

The problem was in the ormconfig.json file. I removed this empty space ("migrations ":) and everything worked just fine.

Sign up to request clarification or add additional context in comments.

Comments

2

you should have synchronized to false synchronize:false

And from the terminal run

npx typeorm migration:generate -n AnyNameYouWant

After that, you can run

npx typeorm migration:run

You may also have to run nest build before running these commands.

1 Comment

I forgot to mention that the migration files I created are to populate some tables (insert statements). They are not related to changes in the database schema... I will edit the question with this info. I tried with synchronize:false but the result was the same.
0

I think this one is to synchronize the database with the schema, and it's not a good idea. "synchronize": true,

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.