I followed the documentation at to create this query:
await dataSource
.createQueryBuilder()
.insert()
.into(Order)
.values(data)
.execute()
However, upon running it, I encountered the error message below:
QueryFailedError: duplicate key value violates unique constraint: "PK_*************"
This issue arose after updating typeorm to the latest version. Previously, I was using a different syntax as shown here:
const orderRepo: Repository<Order> = getConnection().getRepository('order');
await orderRepo.insert(data);
The updated documentation suggests avoiding getConnection and using data source instead. Other operations like updating a user's name still work fine.
The primary key configuration for the Order entity is as follows:
export class Order extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
order_id!: string;
Even though I have cleared all rows in the order table, the error persists:
length: 261,
severity: 'ERROR',
code: '23505',
detail: 'Key (order_id)=(665bbf44-6e68-4250-9247-60ca2353ff8d) already exists
It seems strange since my database should not contain any rows at this point..