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.

"Failed lookup of model or field during internal processing. This means that the internal representation was mutated incorrectly."

See original GitHub issue

A schema that used to work before (preview 21) does not work in preview 22 any more for generation:

datasource db {
  provider = "mysql"
  // other options are: "mysql" and "sqlite"
  url      = "mysql://user:pass@localhost:3306/asd_nest_prisma"
}

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

//generator typegraphql {
//  provider = "node_modules/typegraphql-prisma/generator.js"
//  output   = "../prisma/generated/type-graphql"
//}

model User {
  email        String     @unique
  id           Int        @default(autoincrement()) @id
  mollieApiKey String?
  name         String
  passwordHash String?
  phone        String?
  locations    Location[] @relation(name: "userLocations")

  services         Service[] @relation(name: "userServices", references: owner)
  assignedServices Service[] @relation(name: "assignedServices", references: assignee)

  contacts         Contact[] @relation(name: "userContacts")
  contactsAsTarget Contact[] @relation(name: "targetUsers")

  shop      Shop?       @relation("userShop")
  suppliers Supplier[]
  tokens    UserToken[]
}

model UserToken {
  id        Int    @default(autoincrement()) @id
  randomHex String @unique
  user      User?

  @@index([user])
}

model Contact {
  id         Int   @default(autoincrement()) @id
  showShares Int
  owner      User  @relation(name: "userContacts")
  target     User? @relation(name: "targetUsers")

  @@index([target])
  //@@unique([owner, target])
}

model Location {
  description String
  id          Int     @default(autoincrement()) @id
  name        String
  sku         String?
  user        User?   @relation(name: "userLocations")

  @@index([user])
}

model Order {
  customerEmail String
  customerName  String
  dueDeposit    Float     @default(0)
  dueTotal      Float
  id            Int       @default(autoincrement()) @id
  priceJson     String
  shop          Shop?
  payments      Payment[]

  @@index([shop])
}

model Payment {
  deposit  Int    @default(0)
  id       Int    @default(autoincrement()) @id
  metadata String
  method   String @default("mollie")
  status   String @default("pending")
  total    Float?
  order    Order?

  @@index([order])
}

model Place {
  id       Int       @default(autoincrement()) @id
  name     String
  products Product[] @relation(references: [placeId])
}

model Price {
  dateGeq        DateTime?
  dateLeq        DateTime?
  id             Int       @default(autoincrement()) @id
  name           String
  price          Float
  priceDeposit   Float     @default(0)
  pricePerPerson Int       @default(0)
  seats          Int?
  timeGeq        DateTime?
  timeLeq        DateTime?
  product        Product?

  @@index([product])
}

model Product {
  description             String?
  extraString             String?
  id                      Int     @default(autoincrement()) @id
  name                    String
  requiresExtra           Int     @default(0)
  requiresFlightArrival   Int     @default(0)
  requiresFlightDeparture Int     @default(0)
  requiresName            Int     @default(1)
  place                   Place
  shop                    Shop?
  prices                  Price[]

  @@index([place])
  @@index([shop])
}

model Service {
  canceled      Int       @default(0)
  changed       Int       @default(0)
  clientEmail   String?
  cost          Float?
  datetime      DateTime
  description   String?
  id            Int       @default(autoincrement()) @id
  notCashed     Float
  notes         String?
  paid          Float?
  preview       String
  shared        Int       @default(0)
  toPay         Float
  assignee      User?     @relation(name: "assignedServices", references: id)
  owner         User      @relation(name: "userServices", references: id)
  sourceService Service?  @relation("serviceToservice")
  services      Service[] @relation("serviceToservice")
  supplierIn    Supplier? @relation(name: "suppliedInServices", references: id)
  supplierOut   Supplier? @relation(name: "suppliedOutServices", references: id)
  vehicle       Vehicle?
  contacts      Contact[]

  @@index([vehicle])
  @@index([sourceService])
  @@index([owner])
  @@index([supplierOut])
  @@index([assignee])
  @@index([supplierIn])
}


model Shop {
  id       Int       @default(autoincrement()) @id
  name     String
  prefix   String
  owner    User      @relation("userShop")
  orders   Order[]
  products Product[]
}

model Supplier {
  id    Int     @default(autoincrement()) @id
  name  String?
  vat   String?
  owner User

  servicesSuppliedIn  Service[] @relation(name: "suppliedInServices", references: supplierIn)
  servicesSuppliedOut Service[] @relation(name: "suppliedOutServices", references: supplierOut)

  @@index([owner])
}


model Vehicle {
  id       Int       @default(autoincrement()) @id
  name     String
  owner    User
  services Service[]

  @@index([owner])
}

The error you get on generate and validate:

C:\Users\Jan\Documents\throwaway\matt>npx prisma2@alpha validate
Error: Schema parsing
thread 'main' panicked at 'Failed lookup of model or field during internal processing. This means that the internal representation was mutated incorrectly.', src\libcore\option.rs:1188:5
stack backtrace:
   0: backtrace::backtrace::dbghelp::trace
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace/dbghelp.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src\libstd\sys_common/backtrace.rs:84
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src\libstd\sys_common/backtrace.rs:61
   4: core::fmt::write
             at src\libcore\fmt/mod.rs:1025
   5: std::io::Write::write_fmt
             at src\libstd\io/mod.rs:1426
   6: std::sys_common::backtrace::_print
             at src\libstd\sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src\libstd\sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src\libstd/panicking.rs:193
   9: std::panicking::default_hook
             at src\libstd/panicking.rs:210
  10: std::panicking::rust_panic_with_hook
             at src\libstd/panicking.rs:471
  11: rust_begin_unwind
             at src\libstd/panicking.rs:375
  12: core::panicking::panic_fmt
             at src\libcore/panicking.rs:84
  13: core::option::expect_failed
             at src\libcore/option.rs:1188
  14: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  15: <core::iter::adapters::flatten::Flatten<I> as core::iter::traits::iterator::Iterator>::next
  16: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  17: datamodel::validator::standardise::Standardiser::get_datasource_fields_for_relation_field
  18: datamodel::validator::standardise::Standardiser::standardise
  19: datamodel::validator::validation_pipeline::ValidationPipeline::validate
  20: datamodel::parse_datamodel_internal
  21: datamodel::parse_datamodel
  22: <core::result::Result<core::option::Option<T>,prisma::error::PrismaError> as prisma::data_model_loader::PrismaResultOption<T>>::inner_map
  23: prisma::data_model_loader::load_data_model_components
  24: prisma::cli::CliCommand::dmmf
  25: prisma::main::{{closure}}
  26: <std::future::GenFuture<T> as core::future::future::Future>::poll
  27: tokio::runtime::enter::Enter::block_on
  28: tokio::runtime::thread_pool::ThreadPool::block_on
  29: tokio::runtime::context::enter
  30: tokio::runtime::Runtime::block_on
  31: prisma::main
  32: std::rt::lang_start::{{closure}}
  33: std::rt::lang_start_internal::{{closure}}
             at src\libstd/rt.rs:52
  34: std::panicking::try::do_call
             at src\libstd/panicking.rs:292
  35: __rust_maybe_catch_panic
             at src\libpanic_unwind/lib.rs:78
  36: std::panicking::try
             at src\libstd/panicking.rs:270
  37: std::panic::catch_unwind
             at src\libstd/panic.rs:394
  38: std::rt::lang_start_internal
             at src\libstd/rt.rs:51
  39: main
  40: _tmainCRTStartup
  41: mainCRTStartup
  42: sqlite3GenerateConstraintChecks
  43: sqlite3GenerateConstraintChecks
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
esistgutcommented, Feb 18, 2020
model Contact {
    id         Int      @default(autoincrement()) @id
    showShares Int      @default(0)
    owner      User     @relation("Contact_ownerToUser")
    service    Service?
    target     User?    @relation("Contact_targetToUser")

    @@index([target], name: "Contact.target")
    @@index([owner], name: "owner")
    @@index([service], name: "service")
}

model Location {
    description String  @default("")
    id          Int     @default(autoincrement()) @id
    name        String  @default("")
    sku         String?
    user        User?

    @@index([user], name: "Location.user")
}

model Order {
    customerEmail String    @default("")
    customerName  String    @default("")
    dueDeposit    Float     @default(0)
    dueTotal      Float     @default(0)
    id            Int       @default(autoincrement()) @id
    priceJson     String    @default("")
    shop          Shop?
    payment       Payment[]

    @@index([shop], name: "Order.shop")
}

model Payment {
    deposit  Int    @default(0)
    id       Int    @default(autoincrement()) @id
    metadata String @default("")
    method   String @default("mollie")
    status   String @default("pending")
    total    Float?
    order    Order?

    @@index([order], name: "Payment.order")
}

model Place {
    id      Int       @default(autoincrement()) @id
    name    String    @default("")
    product Product[]
}

model Price {
    dateGeq        DateTime?
    dateLeq        DateTime?
    id             Int       @default(autoincrement()) @id
    name           String    @default("")
    price          Float     @default(0)
    priceDeposit   Float     @default(0)
    pricePerPerson Int       @default(0)
    seats          Int?
    timeGeq        DateTime?
    timeLeq        DateTime?
    product        Product?

    @@index([product], name: "Price.product")
}

model Product {
    description             String?
    extraString             String?
    id                      Int     @default(autoincrement()) @id
    name                    String  @default("")
    requiresExtra           Int     @default(0)
    requiresFlightArrival   Int     @default(0)
    requiresFlightDeparture Int     @default(0)
    requiresName            Int     @default(1)
    place                   Place
    shop                    Shop?
    price                   Price[]

    @@index([place], name: "Product.place")
    @@index([shop], name: "Product.shop")
}

model Service {
    canceled      Int       @default(0)
    changed       Int       @default(0)
    clientEmail   String?
    cost          Float?
    datetime      DateTime
    description   String?
    id            Int       @default(autoincrement()) @id
    notCashed     Float     @default(0)
    notes         String?
    paid          Float?
    preview       String    @default("")
    shared        Int       @default(0)
    toPay         Float     @default(0)
    assignee      User?     @relation("Service_assigneeToUser")
    owner         User      @relation("Service_ownerToUser")
    sourceService Service?  @relation("ServiceToService_sourceService")
    supplierIn    Supplier? @relation("Service_supplierInToSupplier")
    supplierOut   Supplier? @relation("Service_supplierOutToSupplier")
    vehicle       Vehicle?
    contact       Contact[]
    service       Service[] @relation("ServiceToService_sourceService")

    @@index([assignee], name: "Service.assignee")
    @@index([owner], name: "Service.owner")
    @@index([sourceService], name: "Service.sourceService")
    @@index([supplierIn], name: "Service.supplierIn")
    @@index([supplierOut], name: "Service.supplierOut")
    @@index([vehicle], name: "Service.vehicle")
}

model Shop {
    id      Int       @default(autoincrement()) @id
    name    String    @default("")
    prefix  String    @default("")
    owner   User
    order   Order[]
    product Product[]
}

model Supplier {
    id                                    Int       @default(autoincrement()) @id
    name                                  String?
    vat                                   String?
    owner                                 User
    service_Service_supplierInToSupplier  Service[] @relation("Service_supplierInToSupplier")
    service_Service_supplierOutToSupplier Service[] @relation("Service_supplierOutToSupplier")

    @@index([owner], name: "Supplier.owner")
}

model User {
    email                          String      @default("") @unique
    id                             Int         @default(autoincrement()) @id
    mollieApiKey                   String?
    name                           String      @default("")
    passwordHash                   String?
    phone                          String?
    contact_Contact_ownerToUser    Contact[]   @relation("Contact_ownerToUser")
    contact_Contact_targetToUser   Contact[]   @relation("Contact_targetToUser")
    location                       Location[]
    service_Service_assigneeToUser Service[]   @relation("Service_assigneeToUser")
    service_Service_ownerToUser    Service[]   @relation("Service_ownerToUser")
    shop                           Shop?
    supplier                       Supplier[]
    userToken                      UserToken[]
    vehicle                        Vehicle[]
}

model UserToken {
    id        Int    @default(autoincrement()) @id
    randomHex String @default("") @unique
    user      User?

    @@index([user], name: "UserToken.user")
}

model Vehicle {
    id      Int       @default(autoincrement()) @id
    name    String    @default("")
    owner   User
    service Service[]

    @@index([owner], name: "Vehicle.owner")
}
1reaction
janpiocommented, Feb 18, 2020

This shows mostly differences in the @default and the name of @@index - someone else will look deeper into this later and try to understand what is going on. We’ll keep you updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code doesn't indicate errors when wrong field references are ...
This mea ns that the internal representation was mutated incorrectly. ... 'main' panicked at 'Failed lookup of model or field during internal processing....
Read more >
C Users Home OneDrive Graphql examples gt yarn prisma2 dev y ...
... 'main' panicked at 'Failed lookup of model or field during internal processing. This means that the internal representation was mutated incorrectly.
Read more >
Don't let dicts spoil your code - Roman Imankulov
In -place mutations may have different names: pre-processing, populating, enriching, data massage, etc. The result is the same.
Read more >
Handling GraphQL errors like a champ with unions and ...
Error handling can be frustrating in GraphQL. This post shows you how to use unions and interfaces to handle errors in a more...
Read more >
Chapter 12: DNA Damage and Repair – Chemistry
Mutations can occur for many reasons. For example, DNA mutations can be caused by mistakes made by the DNA polymerase during replication. As...
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