6

I have a full operating locale django app, but I'm having troubles while migrating to the site5 server.

When I launch django's syncdb command, all my models' tables are created, but then (I guess when it's creating relationship tables), I got the following error:

_mysql_exceptions.OperationalError: (1071, 'Specified key was too long; max key length is 1000 bytes')

I don't have any problem when I ask django to sync the locale db, this error only occurs in the server...

Any idea?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
dolma33
  • 4,133
  • 6
  • 28
  • 48
  • Maybe you are using an utf8-database, so you possibly exceed the 1000 bytes limit (since a character may take up to 4 bytes). What happens if you try to run `python manage.py sqlall [package]`? – Nedec Dec 28 '10 at 17:07
  • 1
    Could you provide some info on MySQL server versions you're using locally and on the remote server? Also, some models might be useful. It seems like you've got a key on the long VARCHAR column. Maybe these links will give you the clue: http://bugs.mysql.com/bug.php?id=4541 http://bugs.mysql.com/bug.php?id=58187 – dmedvinsky Dec 28 '10 at 18:57
  • what django version are you using? – Mikhail Korobov Dec 29 '10 at 06:43
  • @Nedec: I am using an utf8 db, because it's bilingual eng-esp. sqlall said that none of my keys is longer than 200 chars. – dolma33 Dec 29 '10 at 22:25
  • @d.m mysql 14.14 local, 14.12 server. yes... is that hateful mysql bug... curious that that bug is more than 6 years old and it's still around! – dolma33 Dec 29 '10 at 22:28
  • @mike: 1.1.2 local, 1.1.1 server – dolma33 Dec 29 '10 at 22:28
  • 2
    All the INDEX keys together (*in total*) may not be longer than 1000 bytes. – Nedec Dec 29 '10 at 22:42

2 Answers2

3

http://dev.mysql.com/doc/refman/5.0/en/create-index.html

Prefix support and lengths of prefixes (where supported) are storage engine dependent. For example, a prefix can be up to 1000 bytes long for MyISAM tables, and 767 bytes for InnoDB tables.

http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html

utf8, a UTF-8 encoding of the Unicode character set using one to three bytes per character

You exceed the limitation when you CREATE INDEX.

Although sqlall tells you that none of your key is longer than the limit, you may exceed the limitation because you are using utf8 which uses 3 bytes per character.

One more possible reason is that you have used 'unique_together' in the Meta. This will require a longer index which may cause the issue.

Churix
  • 480
  • 3
  • 14
  • 'unique_together' is the cause for me, any idea how to fix that ? I set 'unique_together' because I need it. – JulienD Jun 13 '16 at 08:00
0

Looks like a bug in django. It may be fixed in 1.2 release by e.g. http://code.djangoproject.com/changeset/13040

Mikhail Korobov
  • 21,908
  • 8
  • 73
  • 65