Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't convert String field to Enum in a migration - Postgres #5893

Closed
ericbiewener opened this issue Feb 27, 2021 · 2 comments · Fixed by prisma/prisma-engines#1703
Closed
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/migration engine Issue in the Migration Engine
Milestone

Comments

@ericbiewener
Copy link

Bug description

I'm using Postgres. I originally created a String field in my prisma schema, but am now trying to convert it to an enum. When I run npx prisma migrate dev --preview-feature, I get this error:

Migration `20210227180413_create_enum_blob_types` failed to apply cleanly to a temporary database.
Error:
Database error: Error querying the database: db error: ERROR: column "type" cannot be cast automatically to type "BlobTypes"
HINT: You might need to specify "USING type::"BlobTypes"".
   0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
             at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:192
   1: sql_migration_connector::sql_database_migration_inferrer::validate_migrations
             at migration-engine/connectors/sql-migration-connector/src/sql_database_migration_inferrer.rs:70
   2: migration_core::api::DevDiagnostic
             at migration-engine/core/src/api.rs:100

How to reproduce

  1. Generate a migration for a new model with a field that has a String type
  2. Generate a new migration that creates an enum and converts the field from the previous step to use that enum --> bug!

Expected behavior

No errors, field is converted to an enum

Prisma information

Original

model Blob {
  id        Int      @default(autoincrement()) @id
  type      String
  data      Json
}

New

model Blob {
  id        Int      @default(autoincrement()) @id
  type      BlobTypes
  data      Json
}

enum BlobTypes {
  NIGHTLY
}

Environment & setup

  • OS: Mac
  • Database: PostgreSQL
  • Node.js 14.15.1
  • Prisma version:
    (FYI I'm using npx when running migratrions)
prisma               : 2.16.1
@prisma/client       : 2.17.0
Current platform     : darwin
Query Engine         : query-engine 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.346.0
Preview Features     : createMany
@tomhoule tomhoule self-assigned this Mar 1, 2021
@tomhoule tomhoule added tech/engines/migration engine Issue in the Migration Engine team/schema Issue for team Schema. process/candidate labels Mar 1, 2021
@tomhoule tomhoule added this to the 2.19.0 milestone Mar 3, 2021
@tomhoule tomhoule added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. and removed process/candidate labels Mar 3, 2021
tomhoule added a commit to prisma/prisma-engines that referenced this issue Mar 4, 2021
@melissafzhang
Copy link

I'm on 2.21.2 and still seeing this issue :(

@tomhoule
Copy link
Contributor

tomhoule commented Jul 1, 2021

@melissafzhang comments in closed issues are often missed. Can you please open a new issue with as much detail as possible, in particular the error you are seeing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/migration engine Issue in the Migration Engine
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants