TypeORM duplicate column error. Workaround it, until it is fixed by maintainers.

Karolis Ščerbiakas • November 25, 2020

typeorm nestjs

I used to get an error like duplicate column in TypeORM. Like it would select same column and alias it twice, when using MySQL 8.0 (what I am using)

`Invitation_role`.`id` AS `Invitation_role_id`, 
`Invitation_role`.`id` AS `Invitation_role_id`, 

Not sure what is causing this, but with some googling around, I came across package which changes the way how TypeORM names selected columns. You can find it here.

Just grab it and add it to your TypORM module config (if you're using Nest) as following:

  namingStrategy: new SnakeNamingStrategy(), // TODO DROP THIS IN TYPEORM 0.30

Now you should be able get back to your work as usual. Now queries are generated like this:


Have a nice day!