添加新字段后,Prisma 架构未正确更新

问题描述

正如标题所述,我在 Next JS 应用程序中使用 prisma 2。我有一个非常简单的架构:

  model User {
  id             Int       @id @default(autoincrement())
  firstName      String
  middleName     String?
  firstLastname  String
  secondLastname String?
  email          String
  role           String
  group          Group?    @relation(fields: [groupId],references: [id])
  groupId        Int?
  activity       Activity? @relation(fields: [activityId],references: [id])
  activityId     Int?
  createdOn      DateTime  @default(Now())
  updatedOn      DateTime  @default(Now())
}

model JobTitle {
  id        Int      @id @default(autoincrement())
  name      String
  createdOn DateTime @default(Now())
  updatedOn DateTime @default(Now())
}

model Group {
  id        Int      @id @default(autoincrement())
  name      String
  users     User[]
  createdOn DateTime @default(Now())
  updatedOn DateTime @default(Now())
}

model Activity {
  id    Int    @id @default(autoincrement())
  name  String
  users User[]
}

我在 User 模型上添加email 字段,并将 groupIdactivityId 字段更改为可选字段。我还将 role 字段的类型更改为 String。我运行 prisma migrateprisma up 来创建一个新的迁移并同步数据库(使用远程 heroku postgresql 数据库作为我的数据源)并且一切运行正常。没有错误。但是,当我尝试创建新用户时,出现以下错误

An error ocurred:  prismaClientValidationError:
Invalid `prisma.user.create()` invocation:

{
  data: {
    firstName: 'John',middleName: 'Edgar',firstLastname: 'Doe',secondLastname: 'Smith',email: 'john@email.com',~~~~~
    role: 'ADMIN',~~~~~~~
+   group: {
+     create?: GroupCreateWithoutUsersInput,+     connect?: GroupWhereUniqueInput,+     connectOrCreate?: GroupCreateOrConnectWithoutusersInput
+   },+   activity: {
+     create?: ActivityCreateWithoutUsersInput,+     connect?: ActivityWhereUniqueInput,+     connectOrCreate?: ActivityCreateOrConnectWithoutusersInput
+   },?   createdOn?: DateTime,?   updatedOn?: DateTime
  }
}

UnkNown arg `email` in data.email for type UserCreateInput. Did you mean `role`?
Argument role: Got invalid value 'ADMIN' on prisma.createOneUser. Provided String,expected RoleCreateOneWithoutUserInput:
type RoleCreateOneWithoutUserInput {
  create?: RoleCreateWithoutUserInput
  connect?: RoleWhereUniqueInput
  connectOrCreate?: RoleCreateOrConnectWithoutUserInput
}
Argument group for data.group is missing.
Argument activity for data.activity is missing.

Note: Lines with + are required,lines with ? are optional.

    at Document.validate (C:\Users\user\Documents\projects\employee-evaluation-app\employee-evaluation-app\node_modules\@prisma\client\runtime\index.js:77411:19)
    at NewprismaClient._executeRequest (C:\Users\user\Documents\projects\employee-evaluation-app\employee-evaluation-app\node_modules\@prisma\client\runtime\index.js:79063:17)
    at C:\Users\user\Documents\projects\employee-evaluation-app\employee-evaluation-app\node_modules\@prisma\client\runtime\index.js:79000:52
    at AsyncResource.runInAsyncScope (node:async_hooks:197:9)
    at NewprismaClient._request (C:\Users\user\Documents\projects\employee-evaluation-app\employee-evaluation-app\node_modules\@prisma\client\runtime\index.js:79000:25)
    at Object.then (C:\Users\user\Documents\projects\employee-evaluation-app\employee-evaluation-app\node_modules\@prisma\client\runtime\index.js:79117:39)
    at runMicrotasks (<anonymous>)
    at processticksAndRejections (node:internal/process/task_queues:93:5) {
  clientVersion: '2.12.0'
}

该操作似乎正在使用先前版本的架构,看看它如何表示电子邮件字段不存在且 role 字段不是字符串类型。此外,groupIdactivityId 字段仍按要求显示。我不知道是否有某种缓存。我已经尝试删除所有迁移并从头开始重新部署所有内容。我什至删除了 heroku 中的数据库并重新开始,但我仍然遇到同样的错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)