sails.js 水线:数据库中未设置 maxLength

sails.js waterline: maxLength not set in DB

我已经为我的一个模型中的一个字段设置了验证规则 maxLength,如果我的输入太长,它会被 sails.js 识别。我的问题是,如果我检查我的数据库,它会显示我的 mysql 数据库的字段长度为 255。我希望它与我的 maxLength 值相同。

我在 Whosebug 上找到了这个: SailsJS - How to specify string attribute length without getting error when creating record?

自从这个已经打开 Sails.js 取得了很大的进步,所以我不知道自定义验证规则是否仍然可行。我不喜欢这个,因为它看起来更像是一个临时的 hack 而不是真正的解决方案。

这是预期的行为还是错误?

我知道您不再需要答案,但也许其他人需要。

为此您必须使用尺寸属性。

文档上说:

If supported in the adapter, can be used to define the size of the attribute. For example in MySQL, size can be specified as a number (n) to create a column with the SQL data type: varchar(n).

就这么用

attributes: {
  name: {
    type: 'string',
    size: 24
  }
}

https://sailsjs.com/documentation/concepts/models-and-orm/attributes#size