prisma: removing `@unique` in `schema.prisma` does not generate SQL to do so

This occurs for me using MySQL 5.7

To reproduce:

  1. Make a model for a new table with a field that is marked as @unique
  2. Generate and run migrations.
  3. Remove the @unique
  4. Generate migrations
  5. There is no ALTER TABLE foo DROP KEY 'table_name_field_name_key; generated in the migrations

This is a problem for me, partly because I need that field not to be unique, but also because the generated prisma client thinks that everything is fine - so the typescript allows statements that then fail due to a unique key violation.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 15 (5 by maintainers)

Most upvoted comments

This issue still exist on latest prisma versions >5.15.0

same here, reopen this issue please @aqrln

@Rodrigodd One the second migrate dev run you could use migrate dev --create-only instead and manually add the SQL to drop the unique index. Then apply it with migrate deploy and your database should match the state of your Prisma schema going forward.