The error QueryFailedError occurs when there is a violation of unique constraint in Typeorm due to

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

Answer №1

After making some modifications to the order entity by removing and then re-adding the primary key column, I was able to successfully synchronize the changes by setting it to true and restarting the server.

If anyone has insight on why this issue occurred in the first place, I would appreciate an explanation!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generate a unique identifier based on data type

Is it feasible to create a function signature based on type in this manner? I have successfully created a function signature as shown below. type Data = { update: boolean }; type Distribution<T> = { on: <K extends keyof T>(key: K, list ...

Compiling problem encountered in Typescript due to error TS2705 related to the ES2015 --lib option

When I run tsc -p . to compile a TypeScript file, I encounter the following error: error TS2705: A async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor o ...

Inferring object keys in Typescript using an array as a basis

I am attempting to generate an object with specific keys based on the values within an array. Below is the code snippet: type AllowedKeys = "foo" | "bar" | "baz" interface Options { keys: AllowedKeys[] } interface AllTy ...

What is the best approach for replacing numerous maps within an rxjs observable array?

Is there a more efficient way to retrieve only 3 items from an array? If you have any suggestions, I would appreciate it! Thank you. loadAsk!: Observable<any[]>; this.loadAsk.pipe( map(arr => arr.sort(() => Math.random() - .5)), map((item ...

Uploading to npm unsuccessful as the specified file in the `main` attribute was not successfully published

I am currently facing an issue while trying to publish a package on npm. The .js file I specified in the package.json is not being included with the package. My project is built using typescript, and I transpile it using the following npm script... "prepu ...

Unlock the power of Env variables on both server and client components with Next.js! Learn how to seamlessly integrate these

In my Next.js app directory, I am facing the need to send emails using Nodemailer, which requires server-side components due to restrictions on client-side sending. Additionally, I am utilizing TypeScript in this project and encountering challenges when tr ...

Translation issues with new line characters in PostgreSQL that are not desired

Within my PostgreSQL database, I have several views that include the following SQL code: select replace( replace(details, E'\n\n', '</text></line><line><text>'||E'\n'), E'\ ...

The error message "vimeo/player.js - Unable to access property 'nativeElement' as it is undefined" appeared

I am encountering difficulties integrating vimeo/player.js into my angular-cli application. There isn't a supporting library for Angular 4, so I'm following the steps in the README.md under "Using with a module bundler". I created a vimeo-player ...

Ensure that the array is completely populated before calling it in Angular

My code starts with an empty array and I need to call a service that works with the populated array. Two service calls are used to populate the array, both fetching elements from an API. The issue is ensuring the last service call waits for the array to be ...

Mastering Inter-Composable Communication in Vue 3: A Guide

Composables in Vue documentation demonstrate how small composition functions can be used for organizing code by composing the app. Discover More About Extracting Composables for Code Organization "Extracted composables act as component-scoped servi ...

Tips for including type definitions when adding elements to an array in TypeScript

Having trouble avoiding the use of 'any' as the type definition when pushing elements into an array? I attempted to specify the type but encountered an error. Here is a snippet of the code: interface answerProps { state: string; answer: s ...

What is the best way to flatten a nested array containing various objects, while extracting values based on the existing property names?

I am seeking a way to flatten a nested array containing different objects and retrieve only the existing values from specific property names within those objects. Specifically, I am interested in extracting all the propertyId values from a nested array co ...

"Exploring the relationship between Typescript and Angular: transforming variables within different

Ever since I made the switch from JavaScript to TypeScript (Version 2.1.5), I have been facing an issue with the code that filters date selection. Despite my efforts, I haven't been able to find a good fix for it yet. Here are the two date-pickers: F ...

Exploring the power of Vue 3 and Vuex with Typescript to access class methods

Can Vuex state be used to access class methods? For example, in this scenario, I am attempting to invoke fullName() to show the user's formatted name. TypeError: store.state.user.fullName is not a function Classes export class User { constructo ...

Retrieve a combination of two columns in any order but not in a specific sequence

Feeling overwhelmed by this issue: There's a table with only 3 columns, each referencing an ID of either a member or a journey. create table sharesRoom ( member1 int references Members, member2 int references Members, journey int references Journe ...

Angular: efficient exchange of information among components

I have a component X that handles a WebSocket. And within component X, I also have multiple presentation components (e.g. Y). Whenever the WebSocket receives a specific message, I need to perform an action in a particular component (e.g. refresh data). To ...

What is the method of utilizing the same approach as ts omit, but implementing it for objects with specific types?

Implementing a left | right join of two objects based on their types is what I aim to achieve. For instance, there is an object config with the default type RequestInit. config = { headers: { 'Content-Type': 'application/json', ...

AppProps in Next.js - Ensure that you have the correct loader set up to handle this specific file type as there are currently no loaders configured for processing it

I've encountered an issue while working on a Next.JS 13.5.6 application in development mode. When I try to connect to the site, I receive an error message. However, everything works fine when I switch to production mode after building and starting the ...

The slice() method in arrays provides a reference to the elements rather than copying

In my file, I am exporting an object in the following manner: export const LINECHART2_DATA = { series: [{ data: [], name: 'HR', }, { etc... }] } The way I import it is like this: import { LINECHART2_DAT ...

Utilizing the spread operator in Typescript interfaces: best practices

I have a react component that includes the spread operator operating on ...other and passed down to lower levels of the component. interface ButtonProps { colourMode: string; regular: boolean; buttonText: string; disabled?: boolean; iconSize?: st ...