typeorm

TypeORM not able to generate migrations


I'm attempting to migrate TypeORM from v2 to v3. I have everything working with my new dataSource.ts file except for generating migrations. Given this command in my package.json "typeorm": "typeorm-ts-node-commonjs", I'm running this CLI command to generate a migration: yarn typeorm migration:generate ./src/migrations/test-migration -d src/dataSource.ts However I get the following error:

Error during migration generation: TypeError: Cannot read properties of undefined (reading 'name') at MysqlQueryRunner.changeColumn....

I was able to locate a related Github ticket to this issue, but the solution presented there was to not have any constructors in the entity class and I have no entity classes that contain a constructor.


Solution

  • This issue had a very specific solution that I will go into but I will also walk through the process by which the problem was found which will be more helpful to general people.

    Exact Problem

    One of our tables had a column that was set as the primary key inside the @Column decorator but didn't have the property unique: true set as well. It would be great if TypeORM had an explicit check for this that through a useful error message but it is what it is.

    Discovering the Problem

    To discover the problem the command to generate the migrations was run: yarn typeorm migration:generate ./src/migrations/test-migration -d src/dataSource.ts in a Javascript debug terminal in vscode with both the "Uncaught Exceptions" and the "Caught Exceptions" breakpoints checked in the Run & Debug window. Once I stepped through the unnecessary errors and found the exception that was thrown in the terminal I was able to poke around and find the values of clonedTable and oldColumn to identify which table and column was the problem.