Skip to content

.save() is throwing duplicate key value violates unique constraint #4122

@W0lfbane

Description

@W0lfbane

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

This was working for me earlier but now it is not. I am using a composite key of three different properties. Every time I try to update and existing row, I get the error QueryFailedError: duplicate key value violates unique constraint "PK_8b1375852f33d30b328388e5a5c".

This is my entity:

'use strict';

import * as _ from 'lodash';
import { Entity, Column, PrimaryColumn, Generated } from "typeorm";


@Entity()
export class Assortment {

	@Column("uuid")
	@Generated("uuid")
	id!: string;

	@PrimaryColumn()
	accountId!: string;

	@PrimaryColumn()
	entityType!: string;

	@PrimaryColumn()
	parentId!: string;

	@Column({
		nullable: true
	})
	parentType!: string;

	@Column('varchar', {
		nullable: true
	})
	sortedIds!: string[];

	@Column('jsonb', {
		nullable: true
	})
	children!: Assortment[];
};

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions