Ao tentar executar o comando npx prisma db seed recebo o erro abaixo no console:
danilo.santos in code-connect on main [!?] via ⬢ v20.11.1 ➜ npx prisma db seed
Environment variables loaded from .env
Running seed command `node prisma/seed.js` ...
Seed OK
Author created {
id: 1,
name: 'Ana Beatriz',
username: 'anabeatriz_dev',
avatar: 'https://raw.githubusercontent.com/viniciosneves/code-connect-assets/main/authors/anabeatriz_dev.png'
}
-- codigo omitido --
PrismaClientValidationError:
Invalid `prisma.post.upsert()` invocation in
/Users/danilo.santos/Documents/Projetos/code-connect/prisma/seed.js:119:25
116 ];
117
118 posts.forEach(async (post) => {
→ 119 await prisma.post.upsert({
where: {
slug: "introducao-ao-react",
? id?: Int,
? AND?: PostWhereInput | PostWhereInput[],
? OR?: PostWhereInput[],
? NOT?: PostWhereInput | PostWhereInput[],
? cover?: StringFilter | String,
? title?: StringFilter | String,
? body?: StringFilter | String,
? markdown?: StringFilter | String,
? createdAt?: DateTimeFilter | DateTime,
? updatedAt?: DateTimeFilter | DateTime,
? authorId?: IntFilter | Int,
? author?: UserScalarRelationFilter | UserWhereInput
},
update: {},
create: {
cover: "https://raw.githubusercontent.com/viniciosneves/code-connect-assets/main/posts/introducao-ao-react.png",
title: "Introdução ao React",
slug: "introducao-ao-react",
body: "Neste post, vamos explorar os conceitos básicos do React, uma biblioteca JavaScript para construir interfaces de usuário. Vamos cobrir componentes, JSX e estados.",
markdown: "```javascript\nfunction HelloComponent() {\n return <h1>Hello, world!</h1>;\n}\n```",
authorId: 1
}
})
Argument `where` of type PostWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.
at wn (/Users/danilo.santos/Documents/Projetos/code-connect/node_modules/@prisma/client/runtime/library.js:29:1363)
at qn.handleRequestError (/Users/danilo.santos/Documents/Projetos/code-connect/node_modules/@prisma/client/runtime/library.js:121:6958)
at qn.handleAndLogRequestError (/Users/danilo.santos/Documents/Projetos/code-connect/node_modules/@prisma/client/runtime/library.js:121:6640)
at qn.request (/Users/danilo.santos/Documents/Projetos/code-connect/node_modules/@prisma/client/runtime/library.js:121:6347)
at async l (/Users/danilo.santos/Documents/Projetos/code-connect/node_modules/@prisma/client/runtime/library.js:130:9616)
at async /Users/danilo.santos/Documents/Projetos/code-connect/prisma/seed.js:119:7 {
clientVersion: '6.1.0'
}
Node.js v20.11.1
An error occurred while running the seed command:
Error: Command failed with exit code 1: node prisma/seed.js
Não consigo avançar no exercicio, poderia me ajudar?? Desde já agradeço.
Este é o seed.js que estou tentando executar.
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
async function main() {
const author = {
name: "Ana Beatriz",
username: "anabeatriz_dev",
avatar: "https://raw.githubusercontent.com/viniciosneves/code-connect-assets/main/authors/anabeatriz_dev.png",
};
const ana = await prisma.user.upsert({
where: {username: author.username},
update: {},
create: author,
})
console.log('Author created', ana)
const posts = [
{
"cover": "https://raw.githubusercontent.com/viniciosneves/code-connect-assets/main/posts/introducao-ao-react.png",
"title": "Introdução ao React",
"slug": "introducao-ao-react",
"body": "Neste post, vamos explorar os conceitos básicos do React, uma biblioteca JavaScript para construir interfaces de usuário. Vamos cobrir componentes, JSX e estados.",
"markdown": "```javascript\nfunction HelloComponent() {\n return <h1>Hello, world!</h1>;\n}\n```",
"authorId": ana.id
}
];
posts.forEach(async (post) => {
await prisma.post.upsert({
where: { slug: post.slug },
update: {},
create:post
})
})
}
console.log('Seed OK')
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})