Cannot update identity column
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[x] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem: I’m trying to update two values from a previously loaded entity. Entity:
@Entity({ name: 'USER' })
export class User extends AbstractBusinessReplicatedEntity {
@PrimaryGeneratedColumn({ name: 'id_user' })
id: number;
@Column({ name: 'ds_email' })
email: string;
@Column({ name: 'bl_locked' })
locked: boolean;
@Column({ name: 'dt_password_expiration' })
@Field()
passwordExpiration: Date;
...
}
When loading and updating the user:
const user: User = await this.userRepository.findOne({
where: {
email,
},
});
...
user.setPasswordExpiration(new Date());
user.setLocked(true);
await this.userRepository.save(user);
the generated query is trying to update user id:
UPDATE "USER" SET "bl_locked" = @1, "dt_password_expiration" = @2, "id_user" = @3 WHERE "id_user" = @0
As you can see I’m not using a partial object for user, as it should be possible to pass the object and Typeorm will deal with primary keys etc, or I’m I doing something wrong?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
How to update Identity Column in SQL Server? - Stack Overflow
19 Answers 19 ; ON GO -- Insert the record which you want to update with new value in the identity column INSERT...
Read more >How to update values in identity column in SQL Server?
You cannot update the value of the identity column in SQL Server using UPDATE statement. · You can delete the existing column and...
Read more >How to resolve "Cannot update identity column 'id'" while ...
This error occurs when an update is called on a table and attempts to set an identity column to a new value, which...
Read more >How to update identity column value in sqlserver - MSDN
You can not update a column with IDENTITY property, you have to insert the record with new value and delete the one with...
Read more >Error in Database Setup: ''Cannot update identity column ID in ...
4) Right-click on dbo.DEPT item, and then select Modify. 5) Select the ID column. On the Column Properties tab, under the Table Designer...
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
+1 . Im facing same problem with .update()
facing same problem when using update()