我使用 ScalaQuery 0.10.0-M1 有以下表定义:
import org.scalaquery.ql.basic.{ BasicTable => Table }
object Nodes extends Table[(String, String)]("node") {
def id = column[String]("id", O.PrimaryKey)
def name = column[String]("name", O.NotNull)
def * = id ~ name
private def uName = index("uk_name", name, unique = true)
}
object Links extends Table[(String, String, String, String)]("link") {
def id = column[String]("id", O.PrimaryKey)
def from = column[String]("from_id", O.NotNull)
def link = column[String]("name", O.NotNull)
def to = column[String]("to_id", O.NotNull)
def * = id ~ from ~ link ~ to
private def ukFromLinkTo = index("uk_FromLinkTo", from ~ link ~ to, unique = true)
private def fkFrom = foreignKey("fk_Link_Node_From", from, Nodes)(_.id)
private def fkTo = foreignKey("fk_Link_Node_To", to, Nodes)(_.id)
}
但是在使用此代码段创建(和打印)ddl 时:
val db = Database.forURL("jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1", driver = "org.h2.Driver")
db withSession {
val ddl = (Nodes.ddl ++ Links.ddl)
ddl.create
println(ddl.createStatements.mkString("\n"))
}
不会生成或打印外键。
这是为什么?我该如何解决?