How to run safe migrations
hello guys I am new to Backend.
i am using prisma. and I have a hairstyle table containing hairstyles and now I added a business to the hairstyle table that references the business table. now I want to run migration but it’s giving me an error that the previous hairstyles in my database references null businesses. how do i solve this
2 Replies
Hi :vmathi: First create a new migration:
Then add your migration to the new created file.
If you want to set a default value for the new field for existing records, you can add an
UPDATE
SQL command before the ALTER TABLE
command that adds the new field. For example, if you're adding a businessId
field to the hairstyle
table and want to set a default value of NULL
for existing records, you could add:
If you want to remove records that do not have corresponding references, you can add a DELETE
SQL command. For example:
Whenever you're ready, run your new migration:
This makes much sense. Thank you very much 👍