【问题标题】:Cannot resolve symbol when inserting data插入数据时无法解析符号
【发布时间】:2016-02-07 15:37:18
【问题描述】:

我正在关注本教程,http://slick.typesafe.com/doc/3.1.0/gettingstarted.html#populating-the-database。当我复制该代码时,它显示“无法解析符号......” my code

我正在使用 IntelliJ

app/controllers/tables.scala:

import slick.driver.H2Driver.api._
import slick.lifted.{ProvenShape, ForeignKeyQuery}


class Suppliers(tag: Tag)
extends Table[(Int, String, String, String, String, String)](tag, "SUPPLIERS") {

def id: Rep[Int] = column[Int]("SUP_ID", O.PrimaryKey)
def name: Rep[String] = column[String]("SUP_NAME")
def street: Rep[String] = column[String]("STREET")
def city: Rep[String] = column[String]("CITY")
def state: Rep[String] = column[String]("STATE")
def zip: Rep[String] = column[String]("ZIP")

def * : ProvenShape[(Int, String, String, String, String, String)] =
  (id, name, street, city, state, zip)
}

class Coffees(tag: Tag)
extends Table[(String, Int, Double, Int, Int)](tag, "COFFEES") {

def name: Rep[String] = column[String]("COF_NAME", O.PrimaryKey)
def supID: Rep[Int] = column[Int]("SUP_ID")
def price: Rep[Double] = column[Double]("PRICE")
def sales: Rep[Int] = column[Int]("SALES")
def total: Rep[Int] = column[Int]("TOTAL")

def * : ProvenShape[(String, Int, Double, Int, Int)] =
  (name, supID, price, sales, total)

def supplier: ForeignKeyQuery[Suppliers, (Int, String, String, String, String, String)] =
  foreignKey("SUP_FK", supID, TableQuery[Suppliers])(_.id)
}

application.conf:

h2mem1 = {
url = "jdbc:h2:mem:test"
driver = org.h2.Driver
connectionPool = disabled
keepAliveConnection = true
}
// im using jdbc:h2:~/test as my URL in H2 Console(port 8082)
// currently using Generic H2 (Embedded)
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:test;MODE=MYSQL;DB_CLOSE_DELAY=-1"
db.default.username=sa
db.default.password=""

构建:

libraryDependencies ++= Seq(
 jdbc,
 cache,
 ws,
 specs2 % Test,
 "com.typesafe.slick" %% "slick" % "3.1.0",
 "com.h2database" % "h2" % "1.4.190",
 "org.slf4j" % "slf4j-nop" % "1.6.4",
 "com.typesafe.slick" %% "slick-codegen" % "3.1.0"
)
libraryDependencies += evolutions

我正在使用 IntelliJ IDE,获得了我需要的所有插件:play、scala 等。我还缺少其他东西吗?还是我的代码

【问题讨论】:

  • 您是如何构建代码的?在 sbt 终端或 Intellij 中? (对不起,如果从教程中很明显,我以前没见过)
  • 未来,请包括准确的错误。它不只是说'无法解析符号......':什么符号?在哪一行?
  • 红字出现错误:Suppliers, Coffees and run(check image)

标签: scala playframework-2.0 h2 slick-3.0


【解决方案1】:

它至少无法解析supplierscoffees,因为您错过了它们的定义:

val suppliers = TableQuery[Suppliers]

val coffees = TableQuery[Coffees]

【讨论】:

  • 我确实将这两行代码放在类数据库中,但我仍然遇到这些错误。 class Database { val suppliers = TableQuery[Suppliers] val coffees = TableQuery[Coffees] val Setup = DBIO.seq( // Create the tables, including primary and foreign keys
猜你喜欢
  • 2021-02-04
  • 1970-01-01
  • 2015-01-13
  • 2018-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
相关资源
最近更新 更多