Bird
0
0

Identify the error in this entity definition:

medium📝 Debug Q6 of 15
NestJS - Database with TypeORM
Identify the error in this entity definition:
@Entity()
export class Product {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'varchar' })
  price: number;
}
AThe class name should be lowercase.
BThe price column type should be numeric, not varchar.
CThe @Entity decorator is missing parentheses.
DThe id property should not use PrimaryGeneratedColumn.
Step-by-Step Solution
Solution:
  1. Step 1: Check the type of the price property

    The property price is a number but the column type is set to 'varchar', which is for strings.
  2. Step 2: Correct column type for numeric values

    For numbers, the column type should be 'int', 'float', or 'decimal', not 'varchar'.
  3. Final Answer:

    The price column type should be numeric, not varchar. -> Option B
  4. Quick Check:

    Matching property and column types [OK]
Quick Trick: Match property types with correct column types [OK]
Common Mistakes:
  • Using string types for numeric properties
  • Ignoring parentheses on decorators
  • Thinking class names must be lowercase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes