Ask Your Question
2

The TypeORM and PostgreSQL encounter QueryFailedError due to the presence of null values in the "price" column.

asked 2023-06-07 05:06:57 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-07 05:15:02 +0000

bukephalos gravatar image

To resolve this QueryFailedError in TypeORM and PostgreSQL due to null values in the "price" column, you can use the "default" property in your entity definition.

For example, in your entity definition file, you can set the "default" property for the "price" column to a default value like zero:

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class Product {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column({ default: 0 })
  price: number;
}

This will ensure that any null values in the "price" column are automatically converted to zero, preventing the QueryFailedError.

You can also use other default values based on your use case, such as an empty string, null, or a specific value that makes sense for your application.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-07 05:06:57 +0000

Seen: 14 times

Last updated: Jun 07 '23