You want to define an entity Order with an auto-generated primary key id, a string customerName limited to 150 characters, and an optional numeric discount that can be null. Which is the correct entity definition?
@PrimaryGeneratedColumn() on id: number creates an auto-incrementing integer primary key. A string type would be incorrect without additional configuration like UUID.
Step 2: Check customerName
@Column({ length: 150 }) with string type creates a VARCHAR(150) column. A number type mismatches.
Step 3: Confirm discount
@Column({ type: 'float', nullable: true }) with optional discount?: number allows null values. Missing nullable: true, wrong type like 'int', or non-optional fails.
Final Answer:
The entity with number id, string customerName({length:150}), optional nullable float discount -> Option D
Quick Check:
Match types, nullable, and optional properties carefully [OK]
Quick Trick:Use nullable: true and optional property for nullable columns [OK]
Common Mistakes:
Mismatching property types and column types
Forgetting to mark nullable columns as optional
Using wrong primary key type
Master "Database with TypeORM" in NestJS
9 interactive learning modes - each teaches the same concept differently