Search code examples
prismaprisma2

Prisma 2: Setting Minimum & Maximum Length of a String type


I am creating a model using Prisma 2 and want to set a minimum and maximum length for one of the fields. I.e., something like this:

model Post {
 ...
 title String @min(3) @max(240)
 ...
}

I just made up the above syntax. I am wondering if something like that exists in Prisma and, if so, how to do it.

Any ideas?

Thanks.


Solution

  • Annotation @db.VarChar

    You can set the maximum length using the annotation @db.VarChar:

    model Post {
     ...
     title String @db.VarChar(240)
     ...
    }
    

    There is no support for adding the minimum length as for now.