Bird
0
0

You want to rename a column in your Prisma model. What is the recommended way to handle this in migrations?

hard📝 Application Q9 of 15
NestJS - Database with Prisma
You want to rename a column in your Prisma model. What is the recommended way to handle this in migrations?
ADelete the old column and add a new one with the new name
BUse the @map attribute to rename the column without losing data
CRename the field in the model and run migrate dev normally
DManually edit the migration SQL files to rename the column
Step-by-Step Solution
Solution:
  1. Step 1: Understand column renaming

    Renaming a column directly can cause data loss if Prisma drops the old column.
  2. Step 2: Use @map attribute

    The @map attribute lets you rename the field in Prisma schema while keeping the database column name unchanged, preserving data.
  3. Final Answer:

    Use the @map attribute to rename the column without losing data -> Option B
  4. Quick Check:

    Use @map to rename columns safely [OK]
Quick Trick: Use @map to rename columns without data loss [OK]
Common Mistakes:
  • Dropping and recreating columns losing data
  • Renaming fields without @map causing errors
  • Editing migration SQL manually risking mistakes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes