Skip to content

Insert fails if PrimaryGeneratedColumn has value #8045

@awn70

Description

@awn70

Issue Description

When you try to insert an entity with repo.insert( entity ) and the entity's PrimaryGeneratedColumn column has a value the operation fails, because typeorm tries to insert the value.
(The column has a value because the entity is a clone of an existing one.)

Expected Behavior

Typeorm ignores the value and returns the new generated value. (typeorm 0.2.34)

Actual Behavior

Insert fails if the PK value already exists.

Violation of PRIMARY KEY constraint 'TTT_PK'. Cannot insert duplicate key in object ...

Steps to Reproduce

My Environment

Dependency Version
Operating System
Node.js version 12.20.2
Typescript version 4.3.5
TypeORM version 0.2.36

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres no
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver yes

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, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions