Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

135
Views
Prisma Migrating issue with Mongo schema and Enums

So I´ve made this schema in first instance

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model User {

  id        String      @id @default(auto()) @map("_id") @db.ObjectId
  email     String      @unique
  role      TipoFichaje @default(JORNADA_ENTRADA)
  createdAt DateTime    @db.Date

}

model Entity {

  id        String   @id @default(auto()) @map("_id") @db.ObjectId
  name      String
  createdAt DateTime @db.Date

}

enum TipoFichaje {
  JORNADA_ENTRADA
  JORNADA_SALIDA
  DESAYUNO
  COMIDA
  FORMACION
  FORMACION3
}

Well then I push the db (prisma db push --preview-feature) and after that I Inserted an object like this:

{
  email: "email@gmail.com"
  role:"FORMACION3"
  createdAt:1970-01-01T00:00:00.000+00:00
}

After that I remove the "Formacion3" ENUM from TipoFichaje and push again (prisma db push)

Like this:

enum TipoFichaje {
      JORNADA_ENTRADA
      JORNADA_SALIDA
      DESAYUNO
      COMIDA
      FORMACION
}

When I try to get the data with Prisma Studio throws this error:

Message: Error in Prisma Client request: 


Invalid `prisma.user.findMany()` invocation:


  Value 'FORMACION3' not found in enum 'TipoFichaje'
  
Query:
{
  "modelName": "User",
  "operation": "findMany",
  "args": {
    "take": 100,
    "skip": 0,
    "select": {
      "id": true,
      "email": true,
      "role": true,
      "createdAt": true
    }
  }
}

My question is: Is it a normal behavior? I mean If i migrate the db with the new changes shouldn't migration fix this? How can I fix this?

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

So, solution came by Janpio (Head of Engineering @ Prisma)

Here

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs