Search code examples
node.jspostgresqlprisma

Inconsistent column data error when using Prisma's findUnique method in a staged server environment


I'm encountering an issue with Prisma while running my endpoint in a staged server environment. The code works perfectly fine on my local development setup, but when I deploy it to the staged server, I receive the following error message from Prisma:

"Invalid prisma.user.findUnique() invocation: Inconsistent column data: Could not convert value '12864831-0edd-4e2e-a066-vb8b04518968' of the field id to type Int."

It seems like there's a problem with converting the id value to an Int type. However, the value '12864831-0edd-4e2e-a066-vb8b04518968' is a UUID and should not be treated as an integer. The issue only occurs in the staged server environment.

Here are some relevant details: Prisma version: 4.16.2 Database type: PostgreSQL Prisma schema definition for the user table:

enum Role {
  USER
  ADMIN
  SUBADMIN
  WORKER
}

model User {
  id        String   @id @default(uuid())
  email     String   @unique
  phone     String   @unique
  role      Role
  name      String?
  password  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

I have already tried the following troubleshooting steps without success:

  1. Ensuring that the Prisma client is up to date on the staged server.
  2. Double-checking the database schema and confirming that the id column is of the correct data type (UUID).
  3. Verifying that the staged server's environment matches the local development environment.

Could someone please guide me on how to resolve this inconsistency issue and allow the findUnique method to work correctly in the staged server environment?


Solution

  • Adding to Adrian's comment, is it possible that your staging environment is missing a migration that causes the id column to be stored as type Int and not as type String? Have you tried using psql (or a similar tool) to determine what the type of the column actually is in staging? In the past, has the id column ever been of type Int?

    This SQL should tell you what your staging database says the type of the column is.

    SELECT pg_typeof(id)
    FROM public."User"
    LIMIT 1;