Home > Software engineering >  Prisma doesn't regenerate interfaces
Prisma doesn't regenerate interfaces

Time:12-29

I have Nest.js project and I use Prisma as my ORM. The problem is next:

I have simple User model:

model User {
    id               String @id @default(uuid()) @db.Uuid

    firstName        String? @map("first_name") @db.Citext
    lastName         String? @map("last_name") @db.Citext
    phoneNumber      String? @map("phone_number") @unique
    email            String  @unique
    password         String
    twitter          String?
    linkedIn         String? @map("linked_in")
    personalWebsite  String? @map("personal_website")
    title            String?
    bio              String?
    tac              Boolean
    accountConfirm   Boolean @map("account_confirm") @default(false)

    verificationCode VerificationCodes[]
    confirmHashes    ConfirmationHashes[]
    session          Sessions?

    updatedAt DateTime @default(now()) @map("updated_at") @updatedAt @db.Timestamptz(6)
    createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)

    @@map("users")
}

What I just did was changing @@map("user") to @@map("users"). I did migration and generate interfaces. Basically, the name of the table within database has been changed, but not interfaces in code. For example, in code I cannot use:

await this.prisma.users.create({...

It says - TS2551: Property 'users' does not exist on type 'PrismaService'.. And what it does is tell me to change it to .user, but that doesn't make sense since I have change it in schema.prisma.

I tried to remove node_modules, reinstall packages, did build a couple of times, but nothing worked for me. What is the problem? Is there a cache? How can I fix it?

CodePudding user response:

@@map changes the name of the database table, not the table generated by Prisma and its TypeScript interfaces.

https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#map-1

In your scenario, the User model will always be referred to via prisma.user. If you want to access it via prisma.users, you have to change the name of the model in Prisma.

  • Related