Cannot update entity because entity id is not set in the entity.
See original GitHub issueIssue Description
When trying to save a record I get Cannot update entity because entity id is not set in the entity.
The payload do not contain any id.
Expected Behavior
Being able to create a new record.
Actual Behavior
Throws the error 'Cannot update entity because entity id is not set in the entity.'
Steps to Reproduce
- Get a transaction,
- Run save method on your entity with said EntityManager and a payload without “id” property.
return this.repo.manager.transaction(entityManager) => {
return entityManager.save(Entity, payload);
})
My Environment
| Dependency | Version |
|---|---|
| Operating System | MacOs 11.2.3 |
| Node.js version | v14.16.1 and v12.18.4 |
| Typescript version | typescript@4.2.4 |
| TypeORM version | typeorm@0.2.32 |
Additional Context
using nest.js: @nestjs/cli@7.6.0 typescript@4.2.3
Relevant Database Driver(s)
-
aurora-data-api -
aurora-data-api-pg -
better-sqlite3 -
cockroachdb -
cordova -
expo -
mongodb -
mysql -
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.
Thanks in advance for any help !
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (3 by maintainers)
Top Results From Across the Web
Typeorm - Cannot update entity because entity id is not set in ...
TypeORM tracks entities with meta-data and most likely the id is still in the meta-data or has gotten in the meta-data.
Read more >typeorm cannot read properties of undefined - You.com
TypeORM: Cannot read property 'id' of undefined - Stack Overflow ... 1 Answer. When using an entity constructor its arguments must be optional....
Read more >EntityHelper and Decorated Entities - MikroORM
To update existing entity, we need to provide its PK in the data , as well as to load that entity first into...
Read more >EntityManager API - typeorm - GitBook
If the entity already exists in the database, then it's updated. If the entity does not exist in the database yet, it's inserted....
Read more >TypeORM - Quick Guide - Tutorialspoint
id is an integer, which doesn't accept duplicate values, but we need to assign values. ... @UpdateDateColumn − It is used to set...
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
For me it was because I wasn’t using
@PrimaryGeneratedColumn() in the entity definition
I don’t know why?
I set primary key
id = nullbefore.save()and there is no error。