Making a column nullable in Slick 3.0 for H2 server

47 views
Skip to first unread message

Suraj Atreya

unread,
May 21, 2015, 10:28:12 AM5/21/15
to scala...@googlegroups.com
I am trying to create a column which can be nullable in H2 running in server mode using Slick 3.0. But, I am not sure how to make a column nullable. Earlier versions of slick had a O.Nullable option per column but in Slick 3.0 it is deprecated.

This is the code I tried to achieve a column as nullable:

  case class TagM(id: Option[Long], name: Option[String])
   
 
class TagMaster(tag: Tag) extends Table[TagM](tag, "TAG_MASTER") {
   
def tagID = column[Long]("TAG_ID", O.PrimaryKey, O.AutoInc)
   
def tagName = column[String]("TAG", O.SqlType("VARCHAR(2046)"), O.Nullable)
   
def * = (tagID.?, tagName.?) <> (TagM.tupled, TagM.unapply)
 
}

Since O.Nullable is deprecated, I tried using this approach too by making the tagName column as Option[String] but this fails to make the column as Nullable.

  case class TagM(id: Option[Long], name: Option[String])
   
 
class TagMaster(tag: Tag) extends Table[TagM](tag, "TAG_MASTER") {
   
def tagID = column[Long]("TAG_ID", O.PrimaryKey, O.AutoInc)
   
def tagName = column[Option[String]]("TAG", O.SqlType("VARCHAR(2046)"))
   
def * = (tagID.?, tagName) <> (TagM.tupled, TagM.unapply)
 
}

I would really appreciate any help as I am unsure about the correct usage.
Reply all
Reply to author
Forward
0 new messages