'TypeORM migrations no changes were found

I'm trying to generate migrations with TypeOrm. When I change an entity, it should detect this change and generate a new migration.

I get the following error message:

No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command

Why am I getting this error message when I changed something in my entities files?

I'm using this command to run TypeOrm:

    "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/typeormConfig.ts",

This is my typeormConfig.ts file:

import { ConnectionOptions } from "typeorm";
import * as path from "path";
import * as dotEnv from 'dotenv'

console.log(path.resolve(__dirname, 'entity/**.entity.ts'))

const result = dotEnv.config({ path: './ormconfig.env' });

if (result.error) {
  throw result.error
}

const config: ConnectionOptions = {
  type: 'mysql',
  host: process.env.TYPEORM_HOST,
  port: +process.env.TYPEORM_PORT,
  username: process.env.TYPEORM_USERNAME,
  password: process.env.TYPEORM_PASSWORD,
  database: process.env.TYPEORM_DATABASE,
  //synchronize: true,
  synchronize: false,
  // migrationsRun: false,
  entities: [path.resolve(__dirname, 'entity/**.entity.*')],
  migrations: [path.resolve(__dirname, 'migration/**')],
  cli: {
    entitiesDir: "src/entity",
    migrationsDir: "src/migration"
  }
}

export default config;


Solution 1:[1]

Update the entities & migrations directory link like this

entities: [__dirname + '/entity/**/*.entity.ts', __dirname + '/entity/**/*.entity.js'],
migrations: [__dirname + '/migration/**/*.ts', __dirname + '/migration/**/*.js'],

It works for me & should work.

Solution 2:[2]

  1. Make sure you configured:
  "migrations": ["db-migrations/*{.ts,.js}"],
  "cli": {
    "migrationsDir": "db-migrations"
  }
  1. Enable synchronize and go to the prev. state of your schema (run the project - this will reset DB changes)
  2. Make the code changes (apply them from git or move to the changed branch)
  3. Disable synchronize and run the project (to make it compile the changes) - it may fail running but it is ok
  4. run typeorm migration:generate -n TestMigration and it will succeed

From there on leave synchronize disabled, just compile the project before running migration:generate

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tushar Roy
Solution 2 eyalyoli