Bird
0
0

Identify the error in the following entity definition:

medium📝 Debug Q14 of 15
NestJS - Database with TypeORM
Identify the error in the following entity definition:
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

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

  @Column({ type: 'varchar', length: 100 })
  name: number;
}
AMissing <code>@Entity()</code> decorator
BProperty type <code>number</code> does not match column type <code>varchar</code>
CPrimary key column missing
DIncorrect import statement
Step-by-Step Solution
Solution:
  1. Step 1: Check property and column type consistency

    The name property is typed as number but the column type is varchar, which expects a string.
  2. Step 2: Confirm other parts are correct

    @Entity() is present, primary key is defined, and imports are correct.
  3. Final Answer:

    Property type number does not match column type varchar -> Option B
  4. Quick Check:

    Property type must match column type [OK]
Quick Trick: Match property type with @Column() type options [OK]
Common Mistakes:
  • Using wrong property type for string columns
  • Forgetting to add @Entity()
  • Missing primary key decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes