Does not resolve correct column name with @JoinColumn
See original GitHub issueIssue Description
if you have a column let’s say “user_id” while using @Column({ name: “user_id” })
and you have other table like photos and you want to reference user_id you get “Error: Referenced column user_id was not found in entity User”
I’m pretty sure it tries to find the column by property name. It should also try finding it by declared value from @Column decorator
Expected Behavior
If it does not fiend property it should look from decorator values…
Actual Behavior
It says:
Error: Referenced column user_id was not found in entity User" even though the column exists
Steps to Reproduce
Create user table like:
@Column({ name: "user_id" })
public userId;
create another table trying to reference it
@Column({ name: "user_id", type: "uuid", nullable: false })
public userId: string;
@JoinColumn({
{ name: "user_id", referencedColumnName: "user_id" },
})
public user: User
My Environment
Dependency | Version |
---|---|
Operating System | win10 |
Node.js version | v14.15.0 |
Typescript version | v4.0.5 |
TypeORM version | v0.2.31 |
Additional Context
Relevant Database Driver(s)
-
aurora-data-api
-
aurora-data-api-pg
-
better-sqlite3
-
cockroachdb
-
cordova
-
expo
-
mongodb
-
maraidb
-
nativescript
-
oracle
-
postgres
-
react-native
-
sap
-
sqlite
-
sqlite-abstract
-
sqljs
-
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don’t know how to start. I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
JPA Cannot resolve column/IntelliJ - java - Stack Overflow
Open the Persistence tool window (View | Tool Windows | Persistence). Right-click the necessary module, persistence unit or session factory, and select Assign ......
Read more >PM80441: DEFAULT JOIN-COLUMN IS NOT BEING ... - IBM
When the SQL for a named query is generated, the "name" attribute of a @JoinColumn is ignored when the "table" attribute.
Read more >How to change the @OneToOne shared primary key column ...
In this article, we are going to see how you can change the @OneToOne shared primary key column name when using JPA and...
Read more >@JoinColumn Annotation Explained | Baeldung
The annotation javax.persistence.JoinColumn marks a column as a join column for an entity association or an element collection. In this quick ...
Read more >Chapter 2. Mapping Entities - Red Hat on GitHub
Note that the logical column name is not necessarily equals to the property name esp when the ... Try hard to fix your...
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 Free
Top 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
Thank you for your reply. This does not function at all for me I found a solution that works.
used “userId” in my referencedColumnName
and in other tables I have
only doing
userId
works for me. Even though it should also work with column nameIf you want to create relation you should use relation decorators. You should read docs but basically what you need to do if you want, for instance, one-to-many relation