Помогите исправить ошибку в создании продукта
при работе с призмой (prisma) у меня возникает ошибка, в которой я бы хотел разобраться и исправить ее.
Я прописал сидер, в котором и создается мой продукт с рандомно генерируемыми полями:
import { PrismaClient, Product } from '@prisma/client';
import * as dotenv from '/4/shoes-store/node_modules/dotenv';
import { faker } from '@faker-js/faker';
//import { generateSlug } from 'src/utils/generate-slug';
//import { randomInt } from 'crypto';
dotenv.config();
const prisma = new PrismaClient()
const createProducts = async (quantity: number) => {
const products: Product[] = []
for (let i = 0; i < quantity; i++) {
const productName = faker.commerce.productName()
const typeName = faker.commerce.department()
const product = await prisma.product.create({
data: {
name: productName,
slug: faker.helpers.slugify(productName),
description: faker.commerce.productDescription(),
price: +faker.commerce.price(100, 400),
images: Array.from({
length: faker.datatype.number({ min: 3, max: 5 })
}).map(() =>
faker.image.imageUrl()
),
type: {
create: {
name: typeName,
slug: faker.helpers.slugify(typeName),
}
},
reviews: {
create: [
{
rating: faker.datatype.number({ min: 3, max: 5 }),
text: faker.lorem.paragraph(),
user: {
connect: {
id: 2
}
}
},
{
rating: faker.datatype.number({ min: 3, max: 5 }),
text: faker.lorem.paragraph(),
user: {
connect: {
id: 3
}
}
},
]
}
}
})
products.push(product)
}
console.log(`Created ${products.length} products :D`)
}
async function main() {
console.log('Start seeding...')
await createProducts(10)
}
main()
.catch(e => console.error(e))
.finally(async () => {
await prisma.$disconnect
})
Вот сама ошибка. Пишет, что я нарушаю ограничение на ненулевость кода бренда.
Но я ведь прописал | null
в index.d.ts
.
/**
* Model Product
*
*/
export type Product = {
id: number
createdAt: Date
updatedAt: Date
name: string
slug: string
description: string
price: Prisma.Decimal
images: string[]
typeId: number
brandId: number | null //вроде как не нулевой
userId: number | null
}
Помогите исправить ошибку, пожалуйста.
Источник: Stack Overflow на русском