2
我有以下使用ScalaQuery表定義0.10.0-M1:ScalaQuery爲什麼不爲外鍵創建ddl?
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"))
}
沒有外鍵獲取生成,也不打印。
這是爲什麼?我該如何解決它?