Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model guessing fails when trying to index a TEXT field #11

Open
cjturner opened this issue Dec 26, 2017 · 2 comments
Open

Model guessing fails when trying to index a TEXT field #11

cjturner opened this issue Dec 26, 2017 · 2 comments

Comments

@cjturner
Copy link

The model guess routine (columns-to-model.js, line 52) can try to create an index for a field of type TEXT. This generates a Sequelize exception (needs a key length).

To workaround this, I put a field.type test around the shouldIndex() call at line 53:

// Make indexes based on column name
    if (field.type != Sequelize.TEXT) {
        if (shouldIndex(field.name)) {
              model.options.indexes.push({ fields: [ field.name ]});
        }
    }
@zzolo
Copy link
Contributor

zzolo commented Dec 27, 2017

This makes sense. Since it's the "auto" index part, it's ok to not deal with text columns, and allow someone to create them in the manual/code version.

@cjturner
Copy link
Author

I have not tracked the source/sequence yet, but the same error occurs (Unhandled rejection SequelizeDatabseError: ER_BLOB_KEY_WITHOUT_LENGTH: BLOB/TEXT column 'name' used in key specification without a key length) under the condition when the destination table already exists (in a MySQL destination).

Interestingly, the field in question is not actually a BLOB/TEXT, but a VARCHAR(280).

If I drop the table, the original mod works, and the table is created.

I assume that, if I was supplying a defined model, this would not occur. I think that a 'save' or 'record' of the guessed model would be a useful feature. Some of the data I am using have a lot of columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants