我正在嘗試將串列添加到模型中,String[]但它給了我這個錯誤:
Field "stats" in model "Player" can't be a list.
The current connector does not support lists of primitive types.
代碼:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = "file:./db.db"
}
model Player {
id String @id @default(cuid())
stats String[]
}
有沒有辦法做到這一點?
uj5u.com熱心網友回復:
僅當您的資料庫本身支持標量串列(陣列)時,資料模型才支持它們。目前,只有在使用 PostgreSQL 或 CockroachDB 時才支持標量串列(因為 MySQL 和SQLite 本身并不支持標量串列)。
https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#-modifier
或者,您可以嘗試使用字串型別的列,并在寫入資料庫之前將陣列轉換為帶有逗號等分隔符的字串。
但是,更新將需要更多的作業,因為您不能使用unsetorpush來自 prisma 的方法,并且如果您的更新取決于當前狀態(例如,第一個查詢獲取當前陣列,第二個查詢更新陣列),則可能必須使用多個查詢。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/480482.html
上一篇:如何顯示“空”(SQLite)
