P
Prisma•3d ago
smykes

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);
});
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
}
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
}
2 Replies
Nurul
Nurul•2d ago
Hey @smykes 👋 Can you check if the BOOK_DATA json file has a title field which consists a number?
smykes
smykesOP•2d ago
Of course, the data export decided the Orwell book 1984 should be a number and not a string. Leaving this open as I will have another question I believe. Thank you @Nurul guess I'm writing a migration file If there is no VARCHAR type, how should I get around this @Nurul I think it might be title String @db.VarChar(200) Nope that wasn't it. How do I do a varchar? So I changed my schema to generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model Book { id String @id @default(uuid()) 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 @db.VarChar(200) user_rating Int year_read Int } and still getting the same typescript error, not sure what to do
Want results from more Discord servers?
Add your server