如何解决Slick 3.0模式创建由于关键规范而导致错误而没有长度的问题 [英] How to get around Slick 3.0 schema creation getting errors due to key specs without length

查看:97
本文介绍了如何解决Slick 3.0模式创建由于关键规范而导致错误而没有长度的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您使用hello-slick-3.0类型安全激活器模板,并尝试将其与MySQL而不是H2一起使用,则创建COFFEES表将导致以下MySQL JDCB驱动程序异常:

If you take the hello-slick-3.0 typesafe activator template and try to use it with MySQL rather than H2, creating the COFFEES table results in the following MySQL JDCB driver exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:在密钥规范中使用的BLOB/TEXT列'COF_NAME'没有密钥长度

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: BLOB/TEXT column 'COF_NAME' used in key specification without a key length

这显然是由于COF_NAME主键字段使用的是SQL TEXT列而不是VARCHAR列,因此导致INNODB密钥的限制为768字节.除了停止使用Slicks DDL并切换到显式MySQL模式创建以外,还有什么可以做的吗?

This apparently is due to COF_NAME primary key field's using a SQL TEXT column, instead of say, a VARCHAR column, and consequently running into INNODB's limit of 768 bytes for keys. Is there anything that can be done here other than stop using Slicks DDL, and switching to explicit MySQL schema creation?

推荐答案

对于Slick 3.2,使用O.Length代替O.Sqltype:

With Slick 3.2, use O.Length instead of O.Sqltype:

def name = column[String]("COF_NAME", O.PrimaryKey, O.Length(100))

这篇关于如何解决Slick 3.0模式创建由于关键规范而导致错误而没有长度的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆