QueryFailedError:` Duplicate column name ' error caused by a bad alias naming
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver: all
TypeORM version: [x] latest [] @next [ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem
Let’s take a simple example with 2 tables with a OneToOne cardinality:
article(#id, category_id., ..) and article_category(#id, ...).
So one article has only one category.
a findOne will generate alias naming like that :
`Article`.`category_id` AS `Article_category_id`,
`Article_category`.`id` AS `Article_category_id`,
And so an error:
QueryFailedError:` Duplicate column name 'Article_category_id'
_Originally posted by @mohamed-badaoui in https://github.com/typeorm/typeorm/issues/1969#issuecomment-687055194_
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:13
Top Results From Across the Web
Duplicate column name with TypeORM in Nestjs
3- my favorite solution is to use name strategy like this: first install npm i --save typeorm-naming-strategies then in your typeorm config file....
Read more >Error when creating view, but everything after SELECT works
error : ORA-00957: duplicate column name 00957. 00000 - "duplicate column name" *Cause: *Action: Trying to alias one column didn't help.
Read more >typeorm/typeorm - Gitter
Then it fails : ER_DUP_FIELDNAME: Duplicate column name \'RoomMessage_sender_id\' Am I missing something / doing something wrong on there? Quentin.
Read more >Cannot query Postgres database that has column names with ...
Drupal's Postgres driver does not quote the table/column/alias identifiers, so Postgres creates them in lowercase and also fails to query them.
Read more >Documentation: 15: SELECT - PostgreSQL
If an alias is written, a column alias list can also be written to provide substitute names for one or more columns of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a pretty annoying bug, in my case, if I remove
{eager: true}
from child relationship’s inverseSide and instead specifyrelations: ['child']
on the findOne method, the problem goes away. It seems to use different name strategy. I have also noticed that this behavior is different on different database drivers. For instance, it currently only happens when I’m using a Mysql database, which sucks because my integration tests all pass since I’m using Sqlite for them.I am seeing the same
ContactEntity
.organization_id
ASContactEntity_organization_id
,ContactEntity_organization
.id
ASContactEntity_organization_id
,“typeorm”: “^0.2.29”,