question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma Model Types only accessible for first model in schema.prisma

See original GitHub issue

Bug description

The types for any models after the first model in schema.prisma aren’t accessible. So when your mouse is hovered over await prisma.secondModel.create() , it shows type any. I traced this error to the index.d.ts file generated by prisma client, apparently

get firstmodelname(): Prisma.FirstModelNameDelegate<GlobalReject>; has a type of interface Prisma.FirstModelNameDelegate<GlobalRejectSettings>;

but for all other models after that get secondmodelname(): Prisma.SecondModelNameDelegate<GlobalReject>; has a type of any.

Based on my observation, it’s because the rest of the models were created outside the Prisma namespace in index.d.ts

How to reproduce

  1. Run npx prisma generate
  2. Hover across any model apart from the first one in ‘schema.prisma’
  3. See type any

Expected behavior

All, methods and properties should show up for all models created in the types.

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["orderByRelation", "selectRelationCount", "filterJson", "nApi", "referentialActions", "orderByAggregateGroup", "interactiveTransactions", "namedConstraints", "fullTextSearch"]
  binaryTargets   = ["native"]
}

datasource db {
  provider = "postgres"
  url      = env("DB_URL")
}

model User {
  id               Int        @id @default(autoincrement())
  firstname        String
  lastname         String
  email            String     @unique
  password         String
  title            String?
  countryCode      String?
  phoneNo          String?
  address          String?
  country          String?
  state            String?
  is_customer      Boolean?
  status           Status     @default(Pending)
  confirmationCode String?    @unique
  resetCode        String?    @unique
  createdAt        DateTime   @default(now())
  updatedAt        DateTime   @updatedAt
  passports        Passport[]

  tokens        String[] //@default()  //(dbgenerated("'array[]::varchar[]"'))
  Traveller     Traveller[]
  FlightBooking FlightBooking[]
  @@map(name: "user")
}

enum Status {
  Pending
  Active
}

// use passport no + nationality as composite pk key
model Passport {
  passportId        Int      @id @default(autoincrement())
  passportNo        String
  nationality       String
  issuingCountry    String
  expiryDate        String
  gender            String
  firstName         String
  lastName          String
  otherNames        String
  dateOfBirth       String
  isTravelCompanion Boolean?
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt
  userId            Int? // relation scalar field  (used in the `@relation` attribute below)
  user              User?    @relation(fields: [userId], references: [id])

  //Passport relation
  traveller Traveller?

  @@map(name: "passport")
}

model Traveller {
  travellerId   Int           @id @default(autoincrement())
  title         String
  firstName     String
  lastName      String
  countryCode   String
  phoneNo       String
  address       String
  state         String
  country       String
  bookingRef    String
  travellerType String?       @default("adult")
  price         String
  currency      String
  isUser        Boolean       @default(false)
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt
  userId        Int? // relation scalar field (used in the '@relation()` attribute below)
  user          User?         @relation(fields: [userId], references: [id])
  flightBooking FlightBooking @relation(fields: [bookingRef], references: [bookingRef])

  // passport relations
  passportId Int
  passport   Passport @relation(fields: [passportId], references: [passportId])

  @@map(name: "traveller")
}

model FlightLeg {
  legId          Int      @id @default(autoincrement())
  legPos         Int //position of the leg in the entire trip [when it includes 1 or more stops]
  depCode        String
  depDateTime    DateTime // depature date => will come from vendor
  desCode        String // destination code => will come from vendor
  arrDateTime    DateTime // arrival date
  legDuration    String // how long the flight will take
  cabinClass     String
  seat           String?
  waitTime       String?  @default("0hrs 0mins") // wait duration at transit airport in hors and minutes (o if legIndex is 0)
  airlineName    String
  airlineCode    String
  depAirport     String
  depAirportCity String
  desAirport     String
  desAirportCity String
  termCondition  Json
  createdAt      DateTime @default(now())
  updatedAt      DateTime @updatedAt


  tripId Int

  //Airport    Airport?    @relation(fields: [depCode], references: [iataCode])
  //airportId  Int?
  FlightTrip FlightTrip @relation(fields: [tripId], references: [tripId])


  //Airport   Airport? @relation(fields: [airportId], references: [id])
  //airportId Int?

  Airport   Airport? @relation(fields: [airportId], references: [id])
  airportId Int?
  @@map(name: "flightLeg")
}

// AnotherUser     AnotherUser? @relation(fields: [authorFirstName, authorLastName], references: [firstName, lastName])

model Airport {
  id               Int         @id @default(autoincrement())
  iataCode         String      @unique
  name             String // airport name
  city             String // city of airport
  citycode         String //iata code for the city
  country          String // country of Airport
  countryCodeTwo   String // 2 character alpha country code
  countryCodeThree String // 3 character alpha country code
  createdAt        DateTime    @default(now())
  updatedAt        DateTime    @updatedAt
  FlightLeg        FlightLeg[]


  @@map(name: "airport")
}

model FlightTrip {
  tripId         Int      @id @default(autoincrement())
  tripPos        Int
  tripDuration   String
  bagCount       Int // total no of bags
  legCount       Int // total no of legs on this trip
  stopCount      Int // total no of stops
  depCode        String
  desCode        String
  depDateTime    DateTime
  arrDateTime    DateTime
  depAirport     String
  depAirportCity String
  desAirport     String
  desAirportCity String
  createdAt      DateTime @default(now())
  updatedAt      DateTime @updatedAt

  // FK
  bookingRef String // FK from flightBooking


  flightLegs    FlightLeg[] //@relation(fields: [tripId], references: [] )
  FlightBooking FlightBooking @relation(fields: [bookingRef], references: [bookingRef])

  @@map(name: "flightTrip")
}

model FlightBooking {
  bookingRef  String   @id
  userId      Int?
  email       String
  countryCode String
  phoneNo     String
  flightType  String
  price       Int
  currency    String
  status      String?
  //tripCount      Int // count of all flight trips(maybe legs too?)
  //travellerCount Int
  paymentId   String?
  //cabinClass String
  adultCount  Int
  childCount  Int
  infantCount Int
  childDOB    String
  airlinePNR  String?
  ticketNo    String?
  vendorPNR   String?
  vendorType  String?
  txref       String
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt

  user User? @relation(fields: [userId], references: [id])

  flightTrips       FlightTrip[]
  travellers        Traveller[]
  flightOffers      FlightOffer?
  flightPostBooking FlightPostBooking[]
  payment           Payment             @relation(fields: [txref], references: [txref])
  @@map(name: "flightBooking")
}

model FlightOffer {
  bookingRef String    @id
  offerId    String
  bookingReq String?   @db.Text
  quoteReq   String?   @db.Text
  detailRes  String?   @db.Text
  reqTime    DateTime?
  resTime    DateTime?
  createdAt  DateTime  @default(now())
  updatedAt  DateTime  @updatedAt

  flightBooking FlightBooking @relation(fields: [bookingRef], references: [bookingRef])
  @@map(name: "flightOffer")
}

model CustomerSupport {
  id             Int      @id @default(autoincrement())
  firstName      String
  lastName       String
  email          String
  phoneNo        String
  countryCode    String
  category       String?
  details        String   @db.Text
  nationality    String?
  purposeOfVisit String?
  previousVisa   String?
  dateOfBirth    String?
  desCountry     String?
  createdAt      DateTime @default(now())
  updatedAt      DateTime @updatedAt

  @@map(name: "customerSupport")
}

model NewsLetter {
  id        Int     @id @default(autoincrement())
  email     String
  channel   String
  isConsent Boolean

  @@map(name: "newsLetter")
}

model FlightPostBooking {
  postBookingId Int       @id @default(autoincrement())
  bookingRef    String
  tripPos       Int
  cabinClass    String?
  depCode       String?
  desCode       String?
  depDate       DateTime?
  cancel        Boolean?
  extraBag      Int?
  otherChange   String?
  seat          String?
  onlineCheckIn Boolean?
  parentChange  String?
  comment       String?
  status        String    @default("open")

  flightBooking FlightBooking @relation(fields: [bookingRef], references: [bookingRef])
  @@map(name: "flightPostBooking")
}

// Payment model
model Payment {
  id        Int     @id @default(autoincrement())
  amount    Int
  remaining Int     @default(0)
  currency  String?
  txref     String  @unique

  flightBooking FlightBooking?


  @@map(name: "payment")
}

Environment & setup

  • OS: [Windows]
  • Database: [PostgreSQL]
  • Node.js version: [v14.17.1]

Prisma Version

Environment variables loaded from .env
prisma                : 2.30.0
@prisma/client        : 2.30.0
Current platform      : windows
Query Engine (Binary) : query-engine 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine      : migration-engine-cli 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine  : introspection-core 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary         : prisma-fmt 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash  : 60b19f4a1de4fe95741da371b4c44a92f4d1adcb
Studio                : 0.422.0
Preview Features      : orderByRelation, selectRelationCount, filterJson, nApi, referentialActions, orderByAggregateGroup, interactiveTransactions, namedConstraints, fullTextSearch

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
NathBabscommented, Jan 29, 2022

Hi @janpio I have fixed it, apparently it was an old typescript version that vscode was using for typescript.tsdk. So I pointed it to a newer version, v4.5.

Also please see this, the Prisma team is meant to implement this https://github.com/prisma/prisma/issues/5726#issuecomment-781466878

To warn users of outdated Typescript versions

Thanks 👍🏿

1reaction
NathBabscommented, Jan 29, 2022

Hi @janpio I just opened the project on Webstorm and it’s working fine, also checked the index.d.ts in Webstorm and there’s no error. Problem seems to be from VsCode parsing the typescript file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data model (Reference) - Prisma
Learn about the concepts for building your data model with Prisma: Models, scalar types, enums, attributes, functions, IDs, default values and more.
Read more >
Prisma schema API (Reference)
Allows you to represent PostgreSQL extensions in your schema. Available in preview for PostgreSQL only in Prisma versions 4.5.0 and later. The following ......
Read more >
Operating against partial structures of your model types - Prisma
As a solution, you can customize the generated model type using Prisma Client's helper types. The User type only contains the model's scalar...
Read more >
Advanced type safety (Reference) - Prisma
Prisma Client provides full type safety for queries, even for partial queries or ... Generated types are TypeScript types that are derived from...
Read more >
Names in the underlying database - Prisma
If you introspect a database the names for indexes and constraints will be added to your schema unless they follow Prisma's naming convention....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found