'Why can I not create a unique index with more than 3 columns in mySQL table?
What I want to realize is adding a unique index for every column in a table. But when I add more than 3 columns to the index, it will throw the error that
Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 3072 bytes```.
I create my table through node.js, and the code is
db.query("CREATE TABLE IF NOT EXISTS tasks (name VARCHAR(255), id VARCHAR(255), `group` VARCHAR(255), owner VARCHAR(255), isComplete BOOL)")
and what I do is
db.query("ALTER TABLE tasks ADD UNIQUE INDEX (name, id, `group`, owner, isComplete)")
When I just add 3 columns, like:
db.query("ALTER TABLE `groups` ADD UNIQUE INDEX (id, name, owner)")
it is okay. So why does this happen?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
