You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scala新手用Slick遇报错:value <> is not a member of...

Fixing "value <> is not a member of (...) in Slick"

Hey there! I've run into this exact issue when I was starting out with Slick too—let's walk through why it's happening and how to fix it quickly.

What's Causing the Error?

The <> method you're using to map between your tuple of Rep values and the User case class relies on implicit conversions and shapes provided by Slick's MySQL Profile. Right now, your imports only pull in specific column type implicits, but you're missing the full set of implicits that let Slick handle the case class mapping.

Your current imports are picking out individual column types:

import slick.jdbc.MySQLProfile._
import slick.jdbc.MySQLProfile.api.stringColumnType
import slick.jdbc.MySQLProfile.api.longColumnType
import slick.jdbc.MySQLProfile.api.timestampColumnType

But these don't include the necessary implicits to support the <> operation between tuples and case classes.

The Fix

Replace those scattered imports with a single import that brings in everything from the MySQL Profile's API:

import slick.jdbc.MySQLProfile.api._

This imports all the required implicits, including the ones that enable the <> mapping function. Also, you can simplify User.unapply(_) to just User.unapply since unapply is already a function that matches the expected signature.

Here's your corrected code:

package models

import slick.jdbc.MySQLProfile.api._
import slick.lifted.Tag

case class User(id: Long, name: String, email: String, PMAccount: String)

class Users(tag: Tag) extends Table[User](tag, "Users") {
  def id = column[Long]("id")
  def name = column[String]("name")
  def email = column[String]("email")
  def PMAccount = column[String]("PMAccount")

  def * = (id, name, email, PMAccount) <> (User.tupled, User.unapply)
}

Quick Note

Slick's api._ import is the standard way to set up your mappings—it includes all column types, implicit conversions, and helper methods you need for most common operations. Avoid picking individual imports unless you have a specific reason to narrow things down.

内容的提问来源于stack exchange,提问作者Benjamin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:49:09