A. The nullable argument cannot be used with unique
B. The unique argument should be a boolean, not a string
C. The column type db.String cannot be used for price
D. The column name price is a reserved keyword
Solution
Step 1: Check the unique argument type
The unique parameter expects a boolean value (True or False), not a string.
Step 2: Identify the error in the code
Passing unique='yes' is invalid and will cause an error.
Final Answer:
The unique argument should be a boolean, not a string -> Option B
Quick Check:
unique must be True or False, not 'yes' [OK]
Hint: unique must be True/False, never a string [OK]
Common Mistakes:
Using string values for boolean parameters
Thinking nullable and unique conflict
Assuming price is reserved keyword
5. You want to create a Flask model column for a user's phone number that must be exactly 10 digits, unique, and cannot be empty. Which declaration is best?
hard
A. phone = db.Column(db.String, unique=False, nullable=False)
B. phone = db.Column(db.Integer, unique=True, nullable=False)
C. phone = db.Column(db.String(10), unique=True, nullable=False)
D. phone = db.Column(db.String(15), nullable=True)
Solution
Step 1: Choose the correct type for phone numbers
Phone numbers often contain leading zeros, so db.String(10) is better than db.Integer.
Step 2: Apply constraints for uniqueness and non-null
Use unique=True to prevent duplicates and nullable=False to disallow empty values.
Final Answer:
phone = db.Column(db.String(10), unique=True, nullable=False) -> Option C