B. Property type number does not match column type varchar
C. Primary key column missing
D. Incorrect import statement
Solution
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.
Step 2: Confirm other parts are correct
@Entity() is present, primary key is defined, and imports are correct.
Final Answer:
Property type number does not match column type varchar -> Option B
Quick Check:
Property type must match column type [OK]
Hint: 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
5. 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?
hard
A. import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Order {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 150 })
customerName: string;
@Column({ type: 'int', nullable: false })
discount: number;
}
B. import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Order {
@PrimaryGeneratedColumn()
id: string;
@Column({ length: 150 })
customerName: string;
@Column({ type: 'float' })
discount: number;
}
C. import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Order {
@PrimaryGeneratedColumn()
id: number;
@Column({ type: 'varchar', length: 150 })
customerName: number;
@Column({ type: 'float', nullable: true })
discount: number;
}
D. import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Order {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 150 })
customerName: string;
@Column({ type: 'float', nullable: true })
discount?: number;
}
Solution
Step 1: Verify primary key 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]
Hint: 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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.