autoInc fields with null default break updates in Postgres

Skip to first unread message

Nathaniel Echols

Jun 19, 2019, 5:01:57 PM6/19/19
to Slick / ScalaQuery
I have several models like this:

case class MyObject(
   uuid: UUID,
   name: String,
   id: Option[Long] = None)

which has a corresponding table definition like this:
class MyObjects(tag: Tag) extends Table[MyObject](tag, "my_objects") {
  def myObjectId = column[Long]("id", O.PrimaryKey, O.AutoInc)
  def uuid = column[UUID]("uuid")
  def name = column[String]("name", O.Length(255))

  override def * = (uuid, name, myObjectId.?) <> (MyObject.tupled, MyObject.apply)

With MySQL or HSQLDB, I can use "upserts" or update existing records by passing the entire case class (as opposed to individual fields), and Slick detects when "id" is None and leaves it out of the update query.  With Postgresql, I instead get this:

org.postgresql.util.PSQLException: ERROR: null value in column "id" violates not-null constraint

I'm already using the BIGSERIAL type for this and other autoInc columns.  What else could I be doing wrong here?  Could this be an actual bug?

(Postgresql 9.6.1, Slick 3.2.3 or 3.3.1)

Reply all
Reply to author
0 new messages