Fail to initialize ORM - key too long


#1

Hi,

I just updated to Gogs version 0.11.34.1122 by reinstalling and copying over my ./conf/app.ini and ./custom/conf/app.ini.
I use mysql as backend so no migration necessary here.
When I start ./gogs web I get this error:
2017/11/27 11:46:15 [FATAL] [...gs/routes/install.go:66 GlobalInit()] Fail to initialize ORM engine: sync database struct error: Error 1071: Specified key was too long; max key length is 767 bytes

This is my ./custom/conf/app.ini
https://paste.debian.net/997780/
This is my ./conf/app.ini
https://paste.debian.net/997782/

pebrille

Edit:
Additionally log from xorm:
2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.045956 Table repository Column size db default is , struct default is 0 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.045991 Table repository Column size db nullable is true, struct nullable is false 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.046003 Table repository Column enable_wiki db default is 1, struct default is true 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.046010 Table repository Column enable_issues db default is 1, struct default is true 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.046020 Table repository Column enable_pulls db default is 1, struct default is true 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.046024 Table repository Column pulls_ignore_whitespace db default is 0, struct default is false 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.046028 Table repository Column pulls_allow_rebase db default is 0, struct default is false 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.046032 Table repository Column is_fork db default is 0, struct default is false 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.046277 Table action Column is_private db default is 0, struct default is false 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.047050 Table mirror Column enable_prune db default is 1, struct default is true 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.047113 Table release Column is_draft db default is 0, struct default is false 2017/11/27 12:44:36 [xorm] [warn] 2017/11/27 12:44:36.047150 Table login_source Column is_actived db default is 0, struct default is false


#2

Anybody? My git is offline for days. Maybe someone can at least point me into the right direction to fix this. ty.


#3

Hi,

I had the same issue seems like gogs is creating database fields with utf8mb4_general_ci encoding. After I updated these fields to utf8_general_ci it was working for me.

The tables that caused this issue for me were “protect_branch” and “protect_branch_whitelist”.

To find this I have changed the file “models/models.go”. I replaced the function the NewEngine with this:

func typeof(v interface{}) string {
    return fmt.Sprintf("%T", v)
}

func NewEngine() (err error) {
        if err = SetEngine(); err != nil {
                return err
        }

        if err = migrations.Migrate(x); err != nil {
                return fmt.Errorf("migrate: %v", err)
        }

        for _, table := range tables {
                log.Trace("Typeof: %s", typeof(table) )
                if err = x.StoreEngine("InnoDB").Sync2(table); err != nil {
                        return fmt.Errorf("sync database struct error: %v\n", err)
                }
        }

        return nil
}

#4

Thank you so much. My gogs is running once again. :kissing_heart:


#5

While it would be better to use a compatible DB, if you’re using a version of MySQL/Mariadb which has the limited index size you can fix it, as indicated by @greso, with the following queries (if you don’t need to support extended utf8 in these columns).

BACK UP YOUR DATABASE FIRST.

alter table protect_branch modify `name` varchar(255) collate  utf8_general_ci; 
alter table protect_branch_whitelist modify `name` varchar(255) collate  utf8_general_ci;

Gogs dosen't restart after upgrade