Error during django's syncdb on server

2019-06-19 00:17发布

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?

2条回答
我只想做你的唯一
2楼-- · 2019-06-19 00:52

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.

查看更多
▲ chillily
3楼-- · 2019-06-19 00:57

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

查看更多
登录 后发表回答