我正在构建一个ReactJS/Node.js世界杯比分预测web应用程序,我刚刚偶然发现了一个奇怪的问题。显然,当我创建数据库时,缺少了一列。
我有一个"种子"。包含世界杯每场比赛数据的文件。每个游戏都是这样的对象:
{
"gameTime": "2022-11-30T15:00:00Z",
"homeTeam": "tun",
"awayTeam": "fra",
"groupLetter": "d",
},
(我只放了一个游戏供参考——还有47个类似的游戏)
Prisma schema:
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
model User {
id String @id @default(cuid())
name String
email String @unique
username String @unique
password String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
guesses Guess[]
}
model Game {
id String @id @default(cuid())
homeTeam String
awayTeam String
gameTime DateTime
groupLetter String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
guesses Guess[]
@@unique([homeTeam, awayTeam, gameTime, groupLetter])
}
model Guess {
id String @id @default(cuid())
userId String
gameId String
homeTeamScore Int
awayTeamScore Int
user User @relation (fields: [userId], references: [id])
game Game @relation (fields: [gameId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([userId, gameId])
}
然而,当我将这些游戏植入我的数据库时,每个游戏对象的情况如下:
{
"id":"cladepd2o0011wh7ca47fo06f",
"homeTeam":"tun",
"awayTeam":"fra",
"gameTime":"2022-11-30T15:00:00.000Z",
"createdAt":"2022-11-12T04:07:07.632Z",
"updatedAt":"2022-11-12T04:07:07.632Z"
}
没有" groupleter "争论。这一点很重要,因为我把它当作过滤器,让我的应用一次只显示一组游戏。然后,当它尝试通过组字母获取游戏时,我得到以下错误:
[GET] /games?groupLetter=a
01:12:46:96
PrismaClientValidationError: Unknown arg `groupLetter` in where.groupLetter for type GameWhereInput.
at Document.validate (/var/task/node_modules/@prisma/client/runtime/index.js:29297:20)
at serializationFn (/var/task/node_modules/@prisma/client/runtime/index.js:31876:19)
at runInChildSpan (/var/task/node_modules/@prisma/client/runtime/index.js:25100:12)
at PrismaClient._executeRequest (/var/task/node_modules/@prisma/client/runtime/index.js:31883:31)
at async PrismaClient._request (/var/task/node_modules/@prisma/client/runtime/index.js:31812:16)
at async list (file:///var/task/api/games/index.js:14:23)
at async bodyParser (/var/task/node_modules/koa-bodyparser/index.js:95:5)
at async cors (/var/task/node_modules/@koa/cors/index.js:108:16) {
clientVersion: '4.4.0'
}
我已经试过放弃游戏了。通过PlanetScale表,并再次推它,但无济于事。我只是不明白为什么" groupleter "在prod数据库中缺少。
哦,在本地它都工作得很好(应用程序显示按组排序的游戏,正是它应该如何)。
希望我没有把它弄得更混乱。你们能帮帮我吗?
没关系…我意识到,在对着屏幕研究了一整夜之后做了大量的试验和错误,我没有重做npx prisma generate
程序。问题解决了。