2012-05-25 29 views
6

Kiedy wykonywane następujące polecenie:Określony klucz był zbyt długi - max długość klucza wynosi 767 bajtów

create table assessment (
    id integer not null auto_increment unique, 
    assignment_weight_type tinyint not null, 
    description varchar(255), 
    end_date datetime not null, 
    from_grade tinyint not null, 
    f_id tinyint not null, 
    name varchar(255) not null, 
    start_date datetime not null, 
    status tinyint not null, 
    weight smallint, 
    school_id integer not null, 
    school_year_id integer not null, 
    s_id integer, primary key (id), 
    unique (name, school_id, school_year_id, from_grade, f_id) 
) ENGINE=InnoDB; 

Mam ten komunikat o błędzie:

Specified key was too long; max key length is 767 bytes 

Używam charset z utf8mb4. Dlaczego otrzymałem komunikat o błędzie?

+0

działa na moim serwerze – zerkms

+0

możliwym duplikatu [# 1071 - Określony klucz był zbyt długi; maksymalna długość klucza to 767 bajtów] (http://stackoverflow.com/questions/1814532/1071-specyfikowany-kluczowy-to-long-max-key- length-is-767-bytes) –

Odpowiedz

5

utf8mb4 używa do czterech bajtów na znak, więc sama nazwa może zająć nawet 1020 bajtów.

+2

+1 pokonaj mnie to. Jeśli chcesz, aby pole miało 255 bajtów, a nie 255 znaków, użyj pola 'varbinary'. –

1

Otrzymałem również ten sam problem, i ustaw wartość dla tych zmiennych w mysql jak poniżej i naprawiono problem.

1.global.innodb_large_prefix = 1

2.innodb_file_format = Barracuda

3.innodb_file_format_max = Barracuda