6

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 ??

}
devmrh
  • 1,171
  • 4
  • 19
  • 46

2 Answers2

9

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.

Griffin
  • 710
  • 2
  • 15
  • 29
2

@Griffin is correct. Additionally, your bio field can be left as is. Prisma sets String type as native database text types by default (only PostgreSQL & SQLite only). You can also set it explicitly regardless of the database:

model User {
  id        Int      @default(autoincrement()) @id
  email     String   @unique
  password  String
  name      String   @db.VarChar(50)
  bio       String   @db.Text
}
user1738546
  • 619
  • 6
  • 15