New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot update entity because entity id is not set in the entity. #7643
Comments
seems like not set primaryColumns in entity |
it is set, that was the strangest part |
same problem, if don't use default property, it's fine |
When opening an issue, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This boils down to ensuring your code that reproduces the problem follows the following guidelines:
MinimalThe more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways:
Don't sacrifice clarity for brevity when creating a minimal example. Use consistent naming and indentation, and include code comments if needed. Use your code editor’s shortcut for formatting code. Don't include any passwords or credentials that must be kept secret. CompleteMake sure all information necessary to reproduce the problem is included in the issue itself. If the problem requires some code as well as some XML-based configuration, include code for both. The problem might not be in the code that you think it is in. Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block. DO NOT use images of code. Copy the actual text from your code editor, paste it into the issus, then format it as code. This helps others more easily read and test your code. ReproducibleTo help you solve your problem, others will need to verify that it exists. Describe the problem. "It doesn't work" isn't descriptive enough to help people understand your problem. Instead, tell other readers what the expected behavior should be. Tell other readers what the exact wording of the error message is, and which line of code is producing it. Use a brief but descriptive summary of your problem as the title of your question. Eliminate any issues that aren't relevant to the problem. If your question isn’t about a compiler error, ensure that there are no compile-time errors. Double-check that your example reproduces the problem! If you inadvertently fixed the problem while composing the example but didn't test it again, you'd want to know that before asking someone else to help. |
@Sufiane it this problem solved ? |
@SFantasy yeah it resolved itself, i guess we can close the issue |
I still have the same issue. How did you resolve it @Sufiane? |
to be honest it went by itself, i destroyed the dist multiple times restarted my app. Are you using class-transformer/validator maybe ? |
I'm not. Thanks for responding |
I found an answer in the thread here You want to set the |
For me it was because I wasn't using |
Thanks for the info! But why should we have to set this option? On 0.2.34, it's working fine without this option, on 0.2.35+, I have to set it. What happened? |
I have the same issue updating from 0.2.34 to latest ( 0.2.41 ). Saving using the |
I don't know why? I set primary key |
@jiayisheji check your sql mode NO_AUTO_VALUE_ON_ZERO affects handling of AUTO_INCREMENT columns. Normally, you generate the next sequence number for the column by inserting either NULL or 0 into it. NO_AUTO_VALUE_ON_ZERO suppresses this behavior for 0 so that only NULL generates the next sequence number. |
@ntedgi Fix Typeorm bug not mysql error. if() {}
else {
if () {}
else {
// If not set null ,else undefined
if (entity[this.propertyName] !== undefined && (returnNulls === false || entity[this.propertyName] !== null))
return { [this.propertyName]: entity[this.propertyName] };
return undefined;
}
} not set null insert: INSERT INTO `users`(`id`, `username`, `password`, `created_at`, `updated_at`) VALUES (DEFAULT, ?, ?, DEFAULT, DEFAULT) --PARAMETERS: ["jiayi", "123456"] mysql insert set null insert: INSERT INTO `users`(`id`, `username`, `password`, `created_at`, `updated_at`) VALUES (null, ?, ?, DEFAULT, DEFAULT) --PARAMETERS: ["jiayi", "123456"] mysql insert I don't know why, I set null to fix Typeorm bugs and mysql insert issues. |
Still needs a proper fix! |
yeah but as @jiayisheji mentioned here, if I set |
This is caused when the table primary key (id) does not have Auto Increment set or marked, |
unfortunately this solution will keep generating new records on upsert, instead of updating the current one, when the constraint is not the primary key. |
I was having this error on an entity with a compound primary key. In our case, the problem was that one of the properties was not being automatically filled.
The solution was to use our custom date decorator (we are using unix_timestamp integer values.)
If you're getting this error, it's probably because your primary key, or part of your primary key is not being populated for whatever reason. You either need to provide a value in code, or use a default value the DB can fill in. In our case, unix_timestamp doesn't work as a default value so we use a @BeforeInsert() to fill in the date columns tagged with @Createdate(). |
Issue 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
Steps to Reproduce
My Environment
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?
Thanks in advance for any help !
The text was updated successfully, but these errors were encountered: