【发布时间】:2021-08-21 15:24:19
【问题描述】:
我正在使用 Prisma - 客户端版本 2.23.0 - 与 mssql 数据库。我正在尝试使用 createMany 为数据库播种。我完全按照 Prisma 文档中的步骤进行操作。我已经成功运行了prisma generate 和prisma db push 命令。我的数据库和表已创建并且 Prisma 连接到它就好了。这是我正在使用的种子函数。
// Prisma create query to seed models in database
const count = await prisma.awDemographics.createMany({
data: [
{
appointed_officials: 'some officials',
awk_state: 'FL',
meeting_schedule: 'MWF',
pending_litigation: 'none',
possible_competition: 'none',
possible_contacts: 'none',
voting_requirements: 'none',
},
{
appointed_officials: 'some officials2',
awk_state: 'FL2',
meeting_schedule: 'MWF2',
pending_litigation: 'none2',
possible_competition: 'none2',
possible_contacts: 'none2',
voting_requirements: 'none2',
},
],
});
}
这是结果
Result:
PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]:
Invalid `prisma.awDemographics.createMany()` invocation:
DEFAULT or NULL are not allowed as explicit identity values.
This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.
Error: Command failed with exit code 1: ts-node --eval "
// @ts-ignore
declare const require: any
console.info('Result:')
const __seed = require('./src/prisma/seed.ts')
const __keys = Object.keys(__seed)
async function runSeed() {
// Execute "seed" named export or default export
if (__keys && __keys.length) {
if (__keys.indexOf('seed') !== -1) {
return __seed.seed()
} else if (__keys.indexOf('default') !== -1) {
return __seed.default()
}
}
}
runSeed()
.then(function (result) {
if (result) {
console.log(result)
}
})
.catch(function (e) {
console.error('Error from seed:')
throw e
})
我可以很好地使用create 函数播种。
这是我的架构:
provider = "prisma-client-js"
previewFeatures = ["microsoftSqlServer"]
}
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}
model AwDemographics {
// @@map(name: "aw_demographics")
id Int @id @default(autoincrement())
appointed_officials String?
awk_state String?
meeting_schedule String?
pending_litigation String?
possible_competition String?
possible_contacts String?
voting_requirements String?
}
【问题讨论】:
-
你能分享你的
schema.prisma吗?您也可以尝试升级到 2.24.0 看看是否可以解决问题? -
感谢您的快速响应。我已经添加了我的架构。将更新到 2.24.0 并再次测试。
-
就是这样!去 2.24.0 工作。非常感谢,这让我发疯了。