skip to Main Content

I’m trying to create a model in Prisma, following the tutorial, which unfortunately doesn’t show how to use a wider variety of MongoDB types.

I see a lot of types in the documentation. For example, I tried using the Integer field as follows:

prisma.schema:

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

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

model Event {
  id        String    @id @default(auto()) @map("_id") @db.ObjectId
  EventId   Integer   @unique
}

When I try to run npx prisma generate I get the error:

$ npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: Get DMMF: Schema parsing - Error while interacting with query-engine-node-api library
Error code: P1012
error: Type "Integer" is neither a built-in type, nor refers to another model, custom type, or enum.
  -->  schema.prisma:15
   |
14 |   id        String    @id @default(auto()) @map("_id") @db.ObjectId
15 |   EventId   Integer
   |

Validation Error Count: 1

Prisma CLI Version : 4.1.1

I get the same errors trying to use Date and Object types. The String type from the tutorialx works fine.

Am I missing a dependency? An import? I can’t find any differences between my setup and the prisma mongo tutorial, aside from the type.

2

Answers


  1. Prisma doesn’t have type called Integer, it has a type Int.You can find the type examples here https://www.prisma.io/docs/concepts/components/prisma-schema/data-model

    Login or Signup to reply.
  2. It looks like the type you should use is called Int. I’m getting that from this Prisma documentation listing the different field types. The field types available are:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search