Create table from slick table definition

冷暖自知 提交于 2021-01-28 05:24:33

问题


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

and table definition:

  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?


回答1:


Unfortunatelly, it is not possible using only slick table definitions. From slick documentation:

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:

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.

Checkout the answer here.



来源:https://stackoverflow.com/questions/46382360/create-table-from-slick-table-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!