question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Composite index name too long

See original GitHub issue

So I was creating a table tonight with 6 fields put into a compound index per the docs.

field: {type:Sequelize.STRING(34), unique:'main'},
another_field: {type:Sequelize.STRING(34), unique:'main'},
a_date_field: {type:Sequelize.STRING(34), unique:'main'},
yet_another_field: {type:Sequelize.STRING(34), unique:'main'},
almost_done_field: {type:Sequelize.STRING(34), unique:'main'},
last_field: {type:Sequelize.STRING(34), unique:'main'}

I’m getting an error from MySQL. ER_TOO_LONG_IDENT “Identifier name is too long”.

Sequelize is combining my field names to create an index name rather than using the ‘main’ string I’m providing.

Is there a way to provide the index name to avoid this issue?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
natesilvacommented, Jan 29, 2018

Please reopen this. This is a bug in lib/associations/belongs-to-many.js, injectAttributes().

https://github.com/sequelize/sequelize/blob/f36db54dd5b031427fd8c52296c614c56421e4ba/lib/associations/belongs-to-many.js#L262

This line creates an index name for a BelongsToMany table, and if the name is longer than 64 characters it will fail on MySQL. On PostgreSQL I believe the name will be truncated to 63 chars, which also is not desirable.

Ideally I’d have the option to specify the index name myself.

1reaction
sushantdhimancommented, Jul 27, 2019

uniqueKey name can be overridden now https://github.com/sequelize/sequelize/pull/9914

Read more comments on GitHub >

github_iconTop Results From Across the Web

Index name too long attachinary/postgresql - Stack Overflow
You are getting the error due to this line in the migration: t.references :attachinariable, polymorphic: true. By default index is true.
Read more >
Migration index too long? Choose the name yourself!
Choose the name yourself! Migrations are a great way of building database schema, but sometimes it's harder to deal with more than just...
Read more >
Specify Name for text Index — MongoDB Manual
Starting in version 4.2, for featureCompatibilityVersion set to "4.2" or greater, MongoDB removes the Index Name Length limit of 127 byte maximum.
Read more >
Indexes for search performance - Cypher Manual - Neo4j
An index created on more than one property for any given label or relationship type is called a composite index. Differences in the...
Read more >
Example: Creating a Composite, Unique Index
index -name specifies the name of the index to be created. If you are creating an index on one column only, then index-name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found