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.

Cannot update identity column

See original GitHub issue

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

github_iconTop GitHub Comments

5reactions
lixaoteccommented, Jun 2, 2020

+1 . Im facing same problem with .update()

3reactions
haziqAhmed7commented, Jan 1, 2021

facing same problem when using update()

Read more comments on GitHub >

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

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