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

huangapple go评论55阅读模式
英文:

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

问题

我在运行端点时遇到了Prisma的问题。在我的本地开发环境中,代码运行正常,但当我部署到分阶段服务器时,我收到来自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.”

似乎存在将id值转换为Int类型的问题。然而,值'12864831-0edd-4e2e-a066-vb8b04518968'是UUID,不应视为整数。该问题仅发生在分阶段服务器环境中。

以下是一些相关细节:
Prisma版本:4.16.2
数据库类型:PostgreSQL
用户表的Prisma模式定义:

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
}

我已经尝试了以下故障排除步骤,但未取得成功:

  1. 确保在分阶段服务器上Prisma客户端已经更新。
  2. 仔细检查数据库模式,并确认id列的数据类型正确(UUID)。
  3. 验证分阶段服务器的环境与本地开发环境匹配。

请问是否能指导我如何解决这个不一致问题,并允许findUnique方法在分阶段服务器环境中正常工作?

英文:

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?

答案1

得分: 1

在Adrian的评论中补充一点,你的分级环境是否可能缺少一个迁移,导致id列以Int类型而不是String类型存储?你尝试过使用psql(或类似的工具)来确定分级环境中实际的列类型吗?在过去,id列是否曾经是Int类型?

这段SQL应该能告诉你在分级数据库中,该列的类型是什么:

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

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;

huangapple
  • 本文由 发表于 2023年7月3日 02:57:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600376.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定