I get this weird error when I'm trying to insert i...
# orm-help
d
I get this weird error when I'm trying to insert into a table
Copy code
Type: PrismaClientKnownRequestError
Message: 
Invalid `prisma.traxRecord.create()` invocation:


  Null constraint violation on the fields: (`id`)

Code: P2011

Query:
prisma.traxRecord.create(
{
  data: {
    back_length: null,
    back_fat: 0,
    frame_score: 0,
    loin_eye_area: 0,
    loin_eye_depth: 0,
    level_1_committed: false,
    level_2_committed: false,
    measured_on: "1970-01-01T00:00:00.000Z",
    birth_weight: 0,
    weaning_weight: 0,
    six_month_weight: 0,
    yearling_weight: 0,
    date_updated: "2021-12-06T01:55:52.424Z",
    type: "SIX_MONTH",
    ipi_definition_id: "",
    goat: {
      connect: {
        id: "c7d04d4d-93e9-43e4-8387-04fb83a3bac8",
      },
    },
    user: {
      connect: {
        id: "9ff02887-f755-49f9-bab2-f8051f66c1b2",
      },
    },
  },
  select: {
    id: true,
    back_length: true,
    back_fat: true,
    frame_score: true,
    loin_eye_area: true,
    loin_eye_depth: true,
    level_1_committed: true,
    level_2_committed: true,
    measured_on: true,
    goat_id: true,
    birth_weight: true,
    weaning_weight: true,
    six_month_weight: true,
    yearling_weight: true,
    user_id: true,
    date_created: true,
    date_updated: true,
    type: true,
    ipi_definition_id: true,
    goat: true,
    user: true,
    six_month_trax_goat: true,
    yearling_trax_goat: true,
  },
}
)
This is my schema, this error is also thrown when using the Prisma Client,
Copy code
model TraxRecord {
  id                String         @id @default(uuid())
  back_length       Int?           @db.UnsignedInt
  back_fat          Int            @db.UnsignedInt
  frame_score       Int            @db.UnsignedInt
  loin_eye_area     Int            @db.UnsignedInt
  loin_eye_depth    Int            @db.UnsignedInt
  level_1_committed Boolean
  level_2_committed Boolean
  measured_on       DateTime       @db.Date
  goat_id           String
  birth_weight      Int            @db.UnsignedInt
  weaning_weight    Int            @db.UnsignedInt
  six_month_weight  Int            @db.UnsignedInt
  yearling_weight   Int            @db.UnsignedInt
  user_id           String
  date_created      DateTime       @default(now())
  date_updated      DateTime       @updatedAt
  type              TraxRecordType
  ipi_definition_id String

  // ### Relations ### //
  goat                Goat  @relation(fields: [goat_id], references: [id], onUpdate: Restrict)
  user                User  @relation(fields: [user_id], references: [id], onUpdate: Restrict)
  six_month_trax_goat Goat? @relation("six_month_trax", fields: [id], references: [six_month_trax_id], onUpdate: Restrict, map: "six_month_trax_id_t_gt")
  yearling_trax_goat  Goat? @relation("yearling_trax", fields: [id], references: [yearling_trax_id], onUpdate: Restrict, map: "yearling_trax_id_t_gt")

  @@index([goat_id], map: "goat_id")
  @@index([user_id], map: "user_id")
  @@map("trax_records")
}

model Goat {
  id                   String       @id @default(uuid())
  animal_id            String?      @db.VarChar(50)
  name                 String       @db.VarChar(50)
  registration_id      String?      @db.VarChar(50)
  tattoo_le            String?      @db.VarChar(50)
  tattoo_re            String?      @db.VarChar(50)
  date_of_birth        DateTime?    @db.Date
  sex_label            GoatSexLabel
  birth_code           Int          @default(1) @db.UnsignedInt
  breed                String?      @db.VarChar(50)
  sire                 String?      @db.VarChar(50)
  sire_registration_id String?      @db.VarChar(50)
  dam                  String?      @db.VarChar(50)
  dam_registration_id  String?      @db.VarChar(50)
  six_month_trax_id    String?
  yearling_trax_id     String?
  user_id              String
  date_created         DateTime     @default(now())
  date_updated         DateTime     @updatedAt

  // ### Relations ### //
  user           User         @relation(fields: [user_id], references: [id], onUpdate: Restrict)
  traxes         TraxRecord[]
  six_month_trax TraxRecord?  @relation("six_month_trax")
  yearling_trax  TraxRecord?  @relation("yearling_trax")

  @@index([six_month_trax_id], map: "six_month_trax_id")
  @@index([user_id], map: "user_id")
  @@index([yearling_trax_id], map: "yearling_trax_id")
  @@map("goats")
}
Does it have something to do with the relations?
a
@Devi Prasad did you solve this by chance>?