在Slick 1.x中,使用自动生成的主键插入表格有点复杂:您必须手动创建一个表格投影,为了插入目的而省略了pk.看起来像Slick 2.x将解决这个问题:
Soft inserts are now the default,i.e. AutoInc columns are automatically skipped when inserting with +=,++=,insert and insertAll. This means that you no longer need separate projections (without the primary key) for inserts.
但是,不得更新2.x文档:
While some database systems allow inserting proper values into AutoInc columns or inserting None to get a created value,most databases forbid this behaviour,so you have to make sure to omit these columns. Slick does not yet have a feature to do this automatically but it is planned for a future release. For now,you have to use a query with a custom projection which does not include the AutoInc column
有没有人知道使用AutoInc插入表中的新2.0语法并获取生成的密钥?
insert的语法与1.0中的相同,只是现在autoinc列会被自动忽略.因此.insert的内容会发生语义变化.如果您想要旧行为(包括它们),则必须调用.forceInsert.