从光滑的表定义创建表 [英] Create table from slick table definition
问题描述
在 PlaySlick 示例中有带有示例数据访问对象的文件.
In PlaySlick sample there is file with sample data access object.
https://github.com/playframework/play-slick/blob/master/samples/basic/app/dao/CatDAO.scala
和表定义:
private class CatsTable(tag: Tag) extends Table[Cat](tag, "CAT") {
def name = column[String]("NAME", O.PrimaryKey)
def color = column[String]("COLOR")
def * = (name, color) <> (Cat.tupled, Cat.unapply)
}
是否可以在不使用游戏演变的情况下使用此定义生成新表?如果没有,为什么?
Is it possible to generate a new table using this definition without using play evolutions? If not, why?
推荐答案
不幸的是,仅使用光滑的表定义是不可能的.来自光滑的文档:
Unfortunatelly, it is not possible using only slick table definitions. From slick documentation:
Slick 本身没有开箱即用的数据库支持迁移,但有一些第三方工具可以很好地使用光滑.
Slick itself does not have out-of-the-box support for database migrations, but there are some third-party tools that work well with Slick.
但他们在此处指出了一些替代方案.
But they point out some alternatives here.
来自一些在灵巧团队工作的人:
From some person that work at the slick team:
Slick 和 Slick DDL Plugin 都只能生成代码来创建或删除您的架构,而不是发展它.所以你还是需要玩演变或类似的东西来修改现有的模式方式.
Both Slick and the Slick DDL Plugin can only generate code to create or delete your schema, not to evolve it. So you still need Play evolutions or something similar to modify an existing schema along the way.
在此处查看答案.
这篇关于从光滑的表定义创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!