简体   繁体   中英

Trouble using "Integer" type in Prisma ORM schema for MongoDB

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.

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

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM