Prisma warns of data loss when changing required field to optional, even when there is a default val

Hi there, I currently a column with this row:
autoDeleteIntroductionsOnLeave Boolean? @default(false)
autoDeleteIntroductionsOnLeave Boolean? @default(false)
and I am trying to change it to
autoDeleteIntroductionsOnLeave Boolean @default(false)
autoDeleteIntroductionsOnLeave Boolean @default(false)
however, even with the default value I get an error while trying to use db push:
@internal/database:db:push: ⚠️ We found changes that cannot be executed:
@internal/database:db:push:
@internal/database:db:push: • Made the column `autoDeleteIntroductionsOnLeave` on table `Guild` required, but there are 5 existing NULL values.
@internal/database:db:push:
@internal/database:db:push:
✔ To apply this change we need to reset the database, do you want to continue? All data will be lost. … no
@internal/database:db:push: ⚠️ We found changes that cannot be executed:
@internal/database:db:push:
@internal/database:db:push: • Made the column `autoDeleteIntroductionsOnLeave` on table `Guild` required, but there are 5 existing NULL values.
@internal/database:db:push:
@internal/database:db:push:
✔ To apply this change we need to reset the database, do you want to continue? All data will be lost. … no
is there a way for me to just tell prisma to use false, as I defined using @default, since it seems quite logical to me. --- System Information: macOS Version: 14.4.1 Chip: Apple M2 Pro Architecture: arm64 JavaScript/TypeScript Project Information: Node.js Version: v20.4.0 TypeScript Version: Version 5.4.3 @prisma/client Version: 5.11.0 prisma Version: 5.11.0
5 Replies
net-tech-
net-tech-OP8mo ago
bump bump bump
janglad
janglad8mo ago
generate the migration with --create-only, edit the generated SQL file to apply false to null values, run the migration
net-tech-
net-tech-OP8mo ago
I'm not using Prisma Migrate im using db push
Nonot
Nonot8mo ago
Prisma is sql client and can help to create migrations but at the end you're the only one who must write it
net-tech-
net-tech-OP8mo ago
I was able to fix the issue in the end. Thanks everyone
Want results from more Discord servers?
Add your server