我正在使用Sails 0.9.8与
MySQL配对,并希望做这样的事情
localhost:1337/player/view/
代替
localhost:1337/player/view/
所以我在模型中加入了这样的东西:
'username' : {
type: 'string',
unique: true,
minLength: 4,
maxLength: 32,
required: true
},
但是每当我举起风帆升降机时我都会遇到错误:
{ [Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes] code: 'ER_TOO_LONG_KEY', index: 0 }
因此,在我浏览模块之后,我发现这是因为默认情况下,Sails在数据库中为string-type属性指定了255的长度.给定长度可以用’size’覆盖,但在创建记录时会导致另一个错误.
'username' : {
type: 'string',
unique: true,
minLength: 4,
maxLength: 32,
size: 32,
required: true
},
创建记录时导致的错误:
Error: Unknown rule: size
at Object.match (npm\node_modules\sails\node_modules\waterline\node_modules\anchor\lib\match.js:50:9)
at Anchor.to (\npm\node_modules\sails\node_modules\waterline\node_modules\anchor\index.js:76:45)
at \npm\node_modules\sails\node_modules\waterline\lib\waterline\core\validations.js:137:33
问题是,如何在创建记录时不指定错误的情况下指定字符串列的大小(以便我可以使用唯一键)?