i want a field to be an array in my mysql schema
I've created my model but in the image field I want it to be an array, so I can insert many images. Is there a solution?
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Product {
id Int @id @default(autoincrement())
title String
description String
category String
price Float
imageURL String
clientId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
client Client @relation(references: [id], fields: [clientId], onDelete: Cascade)
@@map("products")
}
If I write "[]" next to imageURL I get an error:
Field "imageURL" in model "Product" can't be a list. The current connector does not support lists of primitive types.Prisma
3 Replies
@khris it also depends on what database provider xou use,but i think it should be at least an enum
its relational so you want to do a separate image table
Read up on relational models and relationships like one to many relationships you'll learn alot
Hi @keii 👋
MySQL does not support scalar list. That's the reason for that error. See this section of the documentation
You can workaround it by creating a separate
Image
model and establish a one-to-many relationship between Product
and Image
.
For example:
From the example, a Product
can have multiple Image
instances associated with it, and each Image
is linked to a specific Product
via the productId field.