I'm trying to add a List to a model using String[]
but it it gives me this error:
Field "stats" in model "Player" can't be a list.
The current connector does not support lists of primitive types.
Code:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = "file:./db.db"
}
model Player {
id String @id @default(cuid())
stats String[]
}
Is there a way to do this?
CodePudding user response:
Scalar lists (arrays) are only supported in the data model if your database natively supports them. Currently, scalar lists are therefore only supported when using PostgreSQL or CockroachDB (since MySQL and SQLite don't natively support scalar lists).
https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#-modifier
Alternatively, you can try using a string type column and convert your array into string with separator like commas before writing into database.
However, update will require more work as you cannot use unset
or push
method from prisma, and likely have to use multiple queries if your update depends on the current state (e.g. 1st query to get the current array, 2nd query to update array).