这个表定义一直有效,直到我意识到拥有可为空的列意味着我需要使用 Option[String] 而不仅仅是 String。这是我所做的唯一更改,这就是我的代码现在的样子。
class RespondentTableDef(tag: Tag) extends Table[Respondent](tag, "respondent") {
def id = column[Long]("id", O.PrimaryKey)
def uuid = column[String]("uuid")
def version = column[Long]("version")
def task = column[Long]("task")
def firstName = column[Option[String]]("first_name")
def lastName = column[Option[String]]("last_name")
def ageGroup = column[Option[String]]("age_group")
def incomeLevel = column[Option[String]]("income_level")
def employmentStatus = column[Option[String]]("employment_status")
def maritalStatus = column[Option[String]]("marital_status")
def housingStatus = column[Option[String]]("housing_status")
def educationStatus = column[Option[String]]("education_status")
def gender = column[Option[String]]("gender")
override def * =
(id, uuid, version, task, firstName, lastName, ageGroup, incomeLevel, employmentStatus, maritalStatus, housingStatus, educationStatus, gender) <> (Respondent.tupled, Respondent.unapply)
}
编译时出现此错误。
[error] /Users/roy/adivinate/survey2/app/model/Respondent.scala:45: No matching Shape found.
[error] Slick does not know how to map the given types.
[error] Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
[error] Required level: slick.lifted.FlatShapeLevel
[error] Source type: (slick.lifted.Rep[Long], slick.lifted.Rep[String], slick.lifted.Rep[Long], slick.lifted.Rep[Long], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]], slick.lifted.Rep[Option[String]])
[error] Unpacked type: (Long, String, Long, Long, String, String, String, String, String, String, String, String, String)
[error] Packed type: Any
[error] (id, uuid, version, task, firstName, lastName, ageGroup, incomeLevel, employmentStatus, maritalStatus, housingStatus, educationStatus, gender) <> (Respondent.tupled, Respondent.unapply)
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 5 s, completed Dec 21, 2016 8:53:17 PM