Get 'ER_TOO_LONG_KEY error running migrations in the utf8mb4 mysql database
See original GitHub issueWhen running migrations, get the ER_TOO_LONG_KEY, probably because the mysql database charset is utf8mb4. How to make it work?
Here is the database config:
"staging": {
"username": "USERNAME",
"password": "PASSWORD",
"database": "DATABASE",
"host": "HOST",
"dialect": "mysql",
"port": 3306,
"define": {
"charset": "utf8mb4",
"collate": "utf8mb4_general_ci"
}
}
Here are the logs:
Unhandled rejection SequelizeDatabaseError: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes
at Query.formatError (/root/www/smartChat-service-staging/node_modules/sequelize/lib/dialects/mysql/query.js:159:14)
at Query._callback (/root/www/smartChat-service-staging/node_modules/sequelize/lib/dialects/mysql/query.js:35:21)
at Query.Sequence.end (/root/www/smartChat-service-staging/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Query.ErrorPacket (/root/www/smartChat-service-staging/node_modules/mysql/lib/protocol/sequences/Query.js:94:8)
at Protocol._parsePacket (/root/www/smartChat-service-staging/node_modules/mysql/lib/protocol/Protocol.js:274:23)
at Parser.write (/root/www/smartChat-service-staging/node_modules/mysql/lib/protocol/Parser.js:77:12)
at Protocol.write (/root/www/smartChat-service-staging/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/root/www/smartChat-service-staging/node_modules/mysql/lib/Connection.js:96:28)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:764:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:426:10)
at emitReadable (_stream_readable.js:422:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:528:21)
Using version 3.4.1
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Get 'ER_TOO_LONG_KEY error running migrations in the ...
When running migrations, get the ER_TOO_LONG_KEY, probably because the mysql database charset is utf8mb4. How to make it work?
Read more >Migrate MySQL database to UTF8MB4 character encoding
Problem. When a user tries to insert a UTF8 character, which requires 4-byte encoding (e.g. emojis like " 😊🍻"), the “Incorrect String ...
Read more >Migrating MySQL UTF8 to UTF8MB4 problems and questions
Is this a problem? What could I do to fix it? The next step is. ALTER TABLE table_name CHANGE column_name column_name VARCHAR( ...
Read more >An in depth DBA's guide to migrating a MySQL database from ...
During the migration, with either utf8 or utf8mb4 connection settings, we'll find data belonging to the other charset. Is this a problem?
Read more >Migrating Database Charsets to utf8mb4 - Percona
In this blog post, we'll look at options for migrating database charsets to utf8mb4.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Received the same error on a column with unique: true. Adding charset resolved the issue.
This worked for me as well.