Bird
0
0

Given the following Prisma schema change and migration command, what will happen?

medium📝 state output Q13 of 15
NestJS - Database with Prisma
Given the following Prisma schema change and migration command, what will happen?
model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String?
}

// Command run:
npx prisma migrate dev --name addNameField
AThe database schema remains unchanged
BAn error occurs because 'name' field is optional
CA migration file is created adding the optional 'name' field to User table
DThe User table is deleted and recreated
Step-by-Step Solution
Solution:
  1. Step 1: Analyze schema change

    The schema adds an optional 'name' field to the User model, which is a valid change.
  2. Step 2: Understand migrate dev behavior

    Running npx prisma migrate dev --name addNameField creates a migration file reflecting this change and applies it to the database.
  3. Final Answer:

    A migration file is created adding the optional 'name' field to User table -> Option C
  4. Quick Check:

    Optional field added = migration created [OK]
Quick Trick: Optional fields create migrations without errors [OK]
Common Mistakes:
  • Thinking optional fields cause errors
  • Assuming schema stays unchanged without manual DB update
  • Believing migrate dev deletes tables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes