Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ER_TOO_LONG_KEY in SailsJS 1.0 with sails-mysql

Tags:

sails.js

I got this error with sails when I try to sails lift:

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

I just have one model for now: 

module.exports = {

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

It's really simple and I got it from the documentation. I don't understand. It seems it's because of the unique: true.

like image 768
Cyril F Avatar asked Feb 01 '26 01:02

Cyril F


1 Answers

This is due to a combination of factors, but the most pertinent one is that sails-mysql currently defaults to using the utf8mb4 character set for string attributes, to allow the use of emojis and other extended characters. We're working on a patch to make this configurable rather than the default, but in the meantime the quickest workaround is to declare the columnType for your attributes directly:

module.exports = {

datastore: 'default',
tableName: 'sci_user',
attributes: {
    email: {
        type: 'string',
        required: true,
        unique: true,
        columnType: 'varchar'
    },
    password: {
        type: 'string',
        required: true,
        columnType: 'varchar'
    }
}
like image 100
sgress454 Avatar answered Feb 04 '26 00:02

sgress454



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!