Upgrade to 1.5.0 fails during database migration #2187

Closed
opened 2025-11-02 04:26:34 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @fgtham on GitHub (Aug 13, 2018).

  • Gitea version (or commit ref): 1.4.3
  • Git version: 2.11.0
  • Operating system: Raspbian 9.4 (stretch)
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

I'm trying to upgrade from 1.4.3 to 1.5.0 following the docs. Starting gitea 1.5.0 triggers DB migration, which then fails to complete and gitea crashes instead. From gitea.log:

2018/08/13 16:06:29 [I] Log Mode: File(Info)
2018/08/13 16:06:29 [I] XORM Log Mode: File(Info)
2018/08/13 16:06:29 [I] Cache Service Enabled
2018/08/13 16:06:29 [I] Session Service Enabled
2018/08/13 16:06:29 [I] Migration: Reformat and remove incorrect topics
2018/08/13 16:06:29 [I] This migration could take up to minutes, please be patient.
2018/08/13 16:06:30 [...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: Sync2: Error 1071: Specified key was too long; max key length is 767 bytes

The problem might be the MySQL DB character set:

# mysql -e 'show create database gitea'
+----------+-------------------------------------------------------------------+
| Database | Create Database                                                   |
+----------+-------------------------------------------------------------------+
| gitea    | CREATE DATABASE `gitea` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ |
+----------+-------------------------------------------------------------------+

According to this stackoverflow answer, the problem lies within the fact that utf8mb4 uses up to 4 bytes per char. Creating a unique index on a varchar(255) field then exceeds the max key length of 767 bytes, as 4*255 = 1020.

The MySQL docs state that:

Prefix limits are measured in bytes. However, prefix lengths for index specifications in CREATE TABLE, ALTER TABLE, and CREATE INDEX statements are interpreted as number of characters for nonbinary string types (CHAR, VARCHAR, TEXT) and number of bytes for binary string types (BINARY, VARBINARY, BLOB). Take this into account when specifying a prefix length for a nonbinary string column that uses a multibyte character set.

Is there any way to keep using gitea with a utfmb4 character set, or is this simply not supported (yet)?

Originally created by @fgtham on GitHub (Aug 13, 2018). <!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.4.3 - Git version: 2.11.0 - Operating system: Raspbian 9.4 (stretch) - Database (use `[x]`): - [ ] PostgreSQL - [x] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description I'm trying to upgrade from 1.4.3 to 1.5.0 following the docs. Starting gitea 1.5.0 triggers DB migration, which then fails to complete and gitea crashes instead. From gitea.log: ``` 2018/08/13 16:06:29 [I] Log Mode: File(Info) 2018/08/13 16:06:29 [I] XORM Log Mode: File(Info) 2018/08/13 16:06:29 [I] Cache Service Enabled 2018/08/13 16:06:29 [I] Session Service Enabled 2018/08/13 16:06:29 [I] Migration: Reformat and remove incorrect topics 2018/08/13 16:06:29 [I] This migration could take up to minutes, please be patient. 2018/08/13 16:06:30 [...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: Sync2: Error 1071: Specified key was too long; max key length is 767 bytes ``` The problem might be the MySQL DB character set: ``` # mysql -e 'show create database gitea' +----------+-------------------------------------------------------------------+ | Database | Create Database | +----------+-------------------------------------------------------------------+ | gitea | CREATE DATABASE `gitea` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ | +----------+-------------------------------------------------------------------+ ``` According to [this stackoverflow answer](https://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes#16820166), the problem lies within the fact that `utf8mb4` uses up to 4 bytes per char. Creating a unique index on a `varchar(255)` field then exceeds the max key length of 767 bytes, as 4*255 = 1020. The [MySQL docs](https://dev.mysql.com/doc/refman/5.7/en/create-index.html) state that: > Prefix limits are measured in bytes. However, prefix lengths for index specifications in CREATE TABLE, ALTER TABLE, and CREATE INDEX statements are interpreted as number of characters for nonbinary string types (CHAR, VARCHAR, TEXT) and number of bytes for binary string types (BINARY, VARBINARY, BLOB). Take this into account when specifying a prefix length for a nonbinary string column that uses a multibyte character set. Is there any way to keep using gitea with a utfmb4 character set, or is this simply not supported (yet)?
GiteaMirror added the issue/duplicate label 2025-11-02 04:26:34 -06:00
Author
Owner

@SagePtr commented on GitHub (Aug 13, 2018):

Is there any way to keep using gitea with a utfmb4 character set, or is this simply not supported (yet)?

Setting innodb_large_prefix option in my.cnf for example. Or update MySQL to 5.7.7 or more recent version where this option is on by default.

@SagePtr commented on GitHub (Aug 13, 2018): > Is there any way to keep using gitea with a utfmb4 character set, or is this simply not supported (yet)? Setting ```innodb_large_prefix``` option in my.cnf for example. Or update MySQL to 5.7.7 or more recent version where this option is on by default.
Author
Owner

@Pofilo commented on GitHub (Aug 13, 2018):

You should take a look of other issues before !

Duplicate of https://github.com/go-gitea/gitea/issues/4663 which is already a duplicate ;)

@Pofilo commented on GitHub (Aug 13, 2018): You should take a look of other issues before ! Duplicate of https://github.com/go-gitea/gitea/issues/4663 which is already a duplicate ;)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2187