Isa*_*aac 23 heroku-postgres reactjs next.js prisma prisma2
正如标题所述,我在 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[]
}
Run Code Online (Sandbox Code Playgroud)
我email在用户模型上添加了该字段,并将groupId和activityId字段更改为可选。我还将该字段的类型更改role为String. 我运行prisma migrate并prisma 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'
}
Run Code Online (Sandbox Code Playgroud)
该操作似乎正在使用以前版本的架构,因为它表示电子邮件字段不存在并且该role字段不是字符串类型。此外,groupId和activityId字段仍按要求显示。我不知道是否有某种缓存。我已经尝试删除所有迁移并从头开始重新部署所有内容。我什至删除了heroku中的数据库并重新开始,但我仍然遇到相同的错误。
小智 31
npx prisma migrate dev要在运行或后在 VS Code 中修复此问题npx prisma db push,您可以尝试以下方法之一:
Ctrl + Shift + P,然后搜索Restart TS server)上述两种方法需要几分钟才能使 VS Code 再次工作,所以我推荐这种方法:
node_modules\.prisma\client\index.d.ts让 VS Code 重新索引该文件(因为它太大,VS Code 不会重新加载该文件),然后几秒钟后即可工作。Jam*_*mes 20
运行npm install(无需删除 node_modules)然后重新生成 Prisma 类型可以解决此问题。
由于npm i删除了旧的 Prisma 世代,npx prisma generate因此必须从您的schema.prisma.
Ryan 关于为 Prisma 添加安装后脚本的评论也是一个很好的生活质量改进。
编辑: 关闭并打开编辑器(在我的例子中是 VsCode)将修复红线错误。我认为该扩展很难通过新的更改来更新自身。这很痛苦,但如果其他解决方案不起作用的话,它确实有效。
| 归档时间: |
|
| 查看次数: |
33092 次 |
| 最近记录: |