PrismaClientKnownRequestError

I'm getting error that table can't be found. It's not working even after migrate dev --name users and generate commands. model User { id Int @default(autoincrement()) @id email String @unique password String @@map("users") } Model is using @@Map, and running from Nest.JS throws error that table can't be found: Failing on await this.prismaService.user.create The table public.User does not exist in the current database
4 Replies
Prisma AI Help
Prisma AI Help•3w ago
Skipping coffee for instant knowledge! Let's brew that AI answer now. Based on your error message, it appears that Prisma is looking for a table named public.User instead of public.users despite your @@map("users") directive. This is a common issue that can occur for several reasons. Possible causes and solutions: 1. Migration not applied correctly: Even though you've run prisma migrate dev and prisma generate, the migration might not have been applied properly. The error suggests that Prisma is still looking for the original model name rather than the mapped name. 2. Schema changes not reflected: After adding the @@map directive, you need to ensure that: - You've generated a new Prisma client with npx prisma generate - You've restarted your NestJS application 3. Database inconsistency: The database schema might be out of sync with your Prisma schema. Try these solutions: 1. Reset your database and migrations:
npx prisma migrate reset

npx prisma migrate reset

This will drop all tables and reapply migrations. 2. Check your database directly: Verify that the table is actually named users in your database. 3. Ensure you're using the latest Prisma client: Make sure your application is using the newly generated Prisma client after adding the @@map directive. 4. Check for multiple PrismaClient instances: In NestJS, ensure you're using a singleton PrismaService. This issue has been reported by many users, particularly when working with SQLite databases or when there are inconsistencies between the Prisma schema and the actual database schema Github Issue #16617. If these solutions don't work, you might need to delete your migrations folder and create a new initial migration, though this isn't recommended for production environments Github Issue #20303.
Igor Tashevski
Igor TashevskiOP•3w ago
Not working any solution... table users was created ahead of time before running Nest.JS...
Prisma AI Help
Prisma AI Help•3w ago
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul•3w ago
Do you see the table if you run npx prisma studio?

Did you find this page helpful?