Prisma @updatedAt 在创建时产生价值?

Prisma @updatedAt generates value at creation?

我试着按照 prisma 入门在这里 Prisma

当我第一次使用 prisma 客户端创建用户时,updatedAt 字段已经有一个值。我假设它应该只在更新时生成一个值。

这是主要代码

async function main() {
  // ... you will write your Prisma Client queries here

  await prisma.user.create({
    data: {
      email: "test@gmail1.com",
      name: "test",
    },
  });

  const users = await prisma.user.findMany();
  console.log(users);
}

这是我 运行 index.ts 文件

时的结果
[
  {
    id: 1,
    email: 'test@gmail.com',
    name: 'test',
    createdAt: 2022-02-11T03:49:00.090Z,
    updatedAt: 2022-02-11T03:49:00.090Z
  }
]

是的,默认情况下 Prisma 在您创建实体时生成 @updatedAt 值。

您可以通过在应用程序端传递 null 来覆盖它(当然您也需要使字段可为空):

  await prisma.user.create({
    data: {
      email: "test@gmail1.com",
      name: "test",
      // Just pass null here
      updatedAt: null
    },
  });