PrismaP
Prisma14mo ago
10 replies
smykes24

Strange type error in seeding file

I have a strange issue with my seeding file.

import { PrismaClient } from "@prisma/client";
import { v4 as uuidv4 } from "uuid";
import BOOK_DATA from "@/data/data.json";
const prisma = new PrismaClient();

async function main() {
  BOOK_DATA.forEach((book) => {
    if (book["Date Read"] !== "" && book["Date Read"] !== null) {
      prisma.book.upsert({
        create: {
          id: uuidv4(),
          author: book["Author"],
          avg_rating: book["Average Rating"],
          book_id: book["Book Id"],
          date_read: book["Date Read"].split("/").join("-"),
          isbn: book["ISBN"],
          isbn_13: book["ISBN13"],
          month_read: parseInt(book["Date Read"].split("/")[1], 10),
          number_of_pages: book["Number of Pages"],
          publisher: book["Publisher"],
          shelf: book["Exclusive Shelf"],
          title: book["Title"],
          user_rating: book["My Rating"],
          year_read: parseInt(book["Date Read"].split("/")[0], 10),
        },
      });
    }
  });
}

main()
  .then(async () => {
    await prisma.$disconnect();
  })
  .catch(async (e: Error) => {
    console.error(e);
    await prisma.$disconnect();
    process.exit(1);
  });

title is insisting
Type 'string | number' is not assignable to type 'string'.

but my schema and migration files clearly state title is a string. Where is this coming from? It's really strange.

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

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

model Book {
  id        String      @id
  author String
  avg_rating Int
  book_id   Int
  createdAt DateTime @default(now())
  date_read String
  isbn String
  isbn_13 String
  month_read Int
  number_of_pages Int
  publisher String
  shelf String
  title String
  user_rating Int
  year_read Int
}
Was this page helpful?