How to filter if a variable is not in database

Hi, I am fetching users like:
const users = await prisma.users.findMany({
where: {
accountStatus: status as accountStatus,
},
select: {
id: true,
email: true,
name: true,
phoneNumber: true,
didCreated: true,
category: true,
accountStatus: true,
did: true,
createdAt: true,
updatedAt: true,
},
});
const users = await prisma.users.findMany({
where: {
accountStatus: status as accountStatus,
},
select: {
id: true,
email: true,
name: true,
phoneNumber: true,
didCreated: true,
category: true,
accountStatus: true,
did: true,
createdAt: true,
updatedAt: true,
},
});
Now if i dont have a category feild in db in on of user i am getting error:
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
Instead what i want is to leave that category for that user and send remaining data
5 Replies
Nurul
Nurul2mo ago
Hey 👋 Is categories defined as a required field in your schema.prisma file?
kunwar.eth
kunwar.eth2mo ago
I dont think so:
No description
kunwar.eth
kunwar.eth2mo ago
I opened db and deleted category by myself for one user... Now when i load users it gives error:
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
at async orgList (file:///home/shubham/C3i/cemilec-backend/veramo-agent/src/Controllers/Get/UserGetController.ts:49:23) {
code: 'P2032',
clientVersion: '5.14.0',
meta: {
modelName: 'users',
field: 'category',
expected_type: 'String',
found: 'null'
}
}
Nurul
Nurul2mo ago
In your schema, category is defined as a required field as it doesn't have a (?) Could you change it to
category String?
category String?
and after that invoke npx prisma generate` and then try to invoke the same query?
kunwar.eth
kunwar.eth2mo ago
Thanks for the info
Want results from more Discord servers?
Add your server
More Posts
No index found for fulltext search over relation (Planetscale)I'm trying to find "favorited companions" combined with the ability to search through them. As you How to order multiple indexI have a index with multiple fields, i want to order them by company_id at first, but when i'm lookuser not saving on mongodb but works fine with mysqlhi , i was using mysql and switched to test mongodb , followed the docs on mongodb and my User modelUsing createManyAndReturnHi! I'm using Prisma with SQLite, and the LibSQL adapter, and I've just updated to the latest versioPrisma custom flowHello we are trying to make something like our prisma flow like we want to controll when something hPrisma RLS using transactionsHey guys, I hope to get some help here 🙂 I want to implement RLS using a prisma client extension (Typing custom property on a methodI want to add a custom property to a findMany on a particular model to ensure that the user has accePrisma 5.12.1 client has errors accessing postgress db when using with cloudflare workers and the nePrisma 5.12.1 client has errors accessing postgress db when using with cloudflare workers and the ne`PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime` errorI'm having an error when trying to bundle my application with ts up ``` PrismaClientInitializationEForeign key constraint failed on the field: `anime_season_fkey (index)`Getting this error when I try to create a new db entry in prisma, no clue why. Using Postgres risma