ER_TOO_LONG_KEY 在 SailsJS 1.0 中 sails-mysql

ER_TOO_LONG_KEY in SailsJS 1.0 with sails-mysql

当我尝试 sails lift:

时,我遇到了 sails 错误
info: ·• Auto-migrating...  (drop)
error: A hook (`orm`) failed to load!
error:
error: Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes

我现在只有一个模型:

module.exports = {

    datastore: 'default',
    tableName: 'sci_user',
    attributes: {
        email: {
            type: 'string',
            required: true,
            unique: true
        },
        password: {
            type: 'string',
            required: true
        }
    }

它真的很简单,我从文档中得到它。我不明白。似乎是因为 unique: true.

这是多种因素综合造成的,但最相关的是 sails-mysql 目前默认使用 utf8mb4 字符集作为字符串属性,以允许使用表情符号和其他扩展字符。我们正在开发一个补丁,使它成为可配置的而不是默认的,但与此同时,最快的解决方法是直接为您的属性声明 columnType

module.exports = {

datastore: 'default',
tableName: 'sci_user',
attributes: {
    email: {
        type: 'string',
        required: true,
        unique: true,
        columnType: 'varchar'
    },
    password: {
        type: 'string',
        required: true,
        columnType: 'varchar'
    }
}