question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QueryFailedError:` Duplicate column name ' error caused by a bad alias naming

See original GitHub issue

Issue 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:open
  • Created 3 years ago
  • Reactions:14
  • Comments:13

github_iconTop GitHub Comments

4reactions
jcunacommented, Jan 29, 2022

This is a pretty annoying bug, in my case, if I remove {eager: true} from child relationship’s inverseSide and instead specify relations: ['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.

2reactions
luisgarciaalaniscommented, Nov 14, 2020

I am seeing the same ContactEntity.organization_id AS ContactEntity_organization_id, ContactEntity_organization.id AS ContactEntity_organization_id,

@ManyToOne(() => OrganizationEntity, (org) => org.id, { eager: true })
@JoinColumn({ name: 'organization_id' })
organization!: OrganizationEntity;

“typeorm”: “^0.2.29”,

@Entity('organization')
export class OrganizationEntity extends BaseEntity {
    @PrimaryGeneratedColumn()
    id!: number;
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found