Next Cloud安装报错:创建管理员用户失败(SQL键过长问题)
I've run into this exact issue with NextCloud on InfinityFree before—here's how to resolve it:
What's Causing the Error?
The problem stems from a mismatch between NextCloud's default database schema and the limitations of the older MySQL version used by InfinityFree.
NextCloud tries to create the oc_migrations table with a primary key made of two VARCHAR(255) fields. When using UTF8 encoding (required for NextCloud), each character takes up 3 bytes. This makes the total length of the primary key 255*3*2 = 1530 bytes—way over the 1000-byte max key length limit for InnoDB in older MySQL versions.
Solution 1: Manually Create the oc_migrations Table (Recommended)
This is the cleanest fix, as it lets you keep UTF8 encoding while working within the host's constraints:
- Log into your InfinityFree cPanel and open phpMyAdmin.
- Select the database you created for NextCloud.
- Paste this SQL query into the query editor and run it:
CREATE TABLE oc_migrations ( app VARCHAR(166) NOT NULL, version VARCHAR(166) NOT NULL, PRIMARY KEY(app, version) ) DEFAULT CHARACTER SET UTF8 COLLATE utf8_bin ENGINE = InnoDB;
We've reduced the field length to 166—this brings the total key length to 166*3*2 = 996 bytes, which fits under the 1000-byte limit.
4. Go back to the NextCloud installation page, re-enter your admin and database details, and click install. The installer will detect the existing oc_migrations table and skip creating it, avoiding the error.
Solution 2: Temporary Character Set Switch (For Testing Only)
If you just need a quick test setup, you can temporarily switch your database to use latin1 encoding (each character uses 1 byte, so the 255-length fields will only take 510 bytes total):
- In phpMyAdmin, edit your database's default character set to
latin1and collation tolatin1_swedish_ci. - Run the NextCloud installer as normal.
- Important: After installation, you'll need to manually convert all tables back to UTF8/utf8mb4 to support non-ASCII characters (this is tedious, so only use this for quick tests).
内容的提问来源于stack exchange,提问作者Chad Fernandez

