Domanda

mysql> create table newsgroup(
    ->  id integer unsigned NOT NULL AUTO_INCREMENT,
    ->  creater integer unsigned NOT NULL,
    ->  coremember integer unsigned DEFAULT NULL,
    ->  name varchar(300) not null unique,
    ->  description text,
    ->  created datetime not null,
    ->  PRIMARY KEY (id)
    -> );
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
mysql>

Ho cambiato 300 a 250, ed è ok.but io non capisco.

È stato utile?

Soluzione

Il codifica database è impostato su UTF8

Un carattere UTF8 potrebbe richiedere fino a 3 byte in MySQL, così 767 byte è caratteri 255.

La creazione di un indice UNIQUE su tali campi lungo testo non è raccomandato.

Al contrario, creare un indice prefissato pianura

CREATE INDEX ix_newsgroup_name ON newsgroup (name (30))

, che è sufficiente per le ricerche prefissati, e aggiungere un'altra colonna per memorizzare l'hash MD5 che garantirebbe l'unicità.

Altri suggerimenti

767 byte è il limititation prefisso indicato per le tabelle InnoDB. :)

Vedi qui: http: //dev.mysql. com / doc / refman / 5.1 / en / index.html creare-

Stai usando utf-8 o anche un set di caratteri più pesante e quindi ogni simbolo è rappresentato da uno, due, tre o quattro byte. In MySQL utf8 sta per max 3 sequenza di byte, e utf8mb4 per max sequenza di 4 byte.

rimuovere UNICO dal varchar.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top