Removing @default field attribute in schema.prisma file doesn鈥檛 change behaviour when new record is created: default values are still created.
@default field attribute: gender String @default("Female")
genderPreferences String @default("Non-binary")
I then added and removed a few records.
Making sure that all records had a value for gender and genderPreferences, I then removed the @default("...") field attributes for both fields.
prisma migrate save --experimental (confirmed the changes)
prisma migrate up --experimental --verbose provided the following output:
Checking the datasource for potential data loss...
Database Changes:
Migration Database actionsStatus
20200707211115-removed-gender-defaults statements. Done 馃殌
You can get the detailed db changes with prisma migrate up --experimental --verbose
Or read about them in the ./migrations/MIGRATION_ID/README.md
SQL Commands:
-- Start Migrations
-- Migration 20200707211115-removed-gender-defaults
ALTER TABLE "public"."User" ALTER COLUMN "gender" DROP DEFAULT,
ALTER COLUMN "genderPreferences" DROP DEFAULT;
-- End Migrations
馃殌 Done with 1 migration in 5.25s.
That removing the @default field attribute would also remove its corresponding behaviour.
@prisma/[email protected]
@prisma/[email protected]
2.1.112.6.0One possible scenario for this behaviour is that you ran the migration, and the database-level default was dropped, but your client was not re-generated, so you still have the client with the defaults, and the query engine inserts them. Could it be that you did not re-generate the client after the migration?
That did it, thanks @tomhoule!
Most helpful comment
One possible scenario for this behaviour is that you ran the migration, and the database-level default was dropped, but your client was not re-generated, so you still have the client with the defaults, and the query engine inserts them. Could it be that you did not re-generate the client after the migration?