Migrate: Removal of "@default" in schema doesn鈥檛 change behaviour

Created on 8 Jul 2020  路  2Comments  路  Source: prisma/migrate

Bug description

Removing @default field attribute in schema.prisma file doesn鈥檛 change behaviour when new record is created: default values are still created.

How to reproduce

  1. I added the following fields, but since database already had existing records, I added a @default field attribute:
  gender            String        @default("Female")
  genderPreferences String        @default("Non-binary")
  1. I then added and removed a few records.

  2. Making sure that all records had a value for gender and genderPreferences, I then removed the @default("...") field attributes for both fields.

  3. prisma migrate save --experimental (confirmed the changes)

  4. 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.
  1. However, when I create a new record, it still adds the specific gender defaults I had set temporarily in step 1.

Expected behavior

That removing the @default field attribute would also remove its corresponding behaviour.

Prisma information

@prisma/[email protected]
@prisma/[email protected]

Environment & setup

  • OS: macOS
  • Database: AWS RDS (PostgreSQL)
  • Prisma version: 2.1.1
  • Node.js version: 12.6.0

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?

All 2 comments

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?

That did it, thanks @tomhoule!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julien1619 picture julien1619  路  4Comments

hamidb80 picture hamidb80  路  4Comments

nickreynke picture nickreynke  路  4Comments

ff-anthony-soto picture ff-anthony-soto  路  3Comments

steebchen picture steebchen  路  3Comments