Search code examples
prismaprisma-graphqlprisma2

prisma2 set length and column type in prisma schema


how can i set string(varchar) length for string type be 50 and define a column be TEXT in prisma schema, for user table i want name be varchar(50) and bio be Text column. im creating my tables by prisma migrate save and up.

model User {

  id        Int      @default(autoincrement()) @id
  email     String   @unique
  password  String
  name      String   ***** varchar 50****
  bio       String  *****TEXT ??

}

Solution

  • The following feature was added recently in v2.17.0. You can specify database types in a scalar field's attributes using @db. followed by the desired native database type attribute specified by Prisma. For varchar, use the following for PostgreSQL.

    model User {
      id        Int      @default(autoincrement()) @id
      email     String   @unique
      password  String
      name      String   @db.VarChar(50)
    }
    

    For more database types, refer to the Prisma Schema API docs.