-
-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
django migrate raise mysql error (1071, 'Specified key was too long; max key length is 767 bytes') #473
Comments
Hello! I also face this problem. I have try different solutions but each with different issues behind. Overriding the max_length in models.py is one of the solution. Actually the max_length can be set as 190 (767 / 4 = 191.75, setting 190 for a 10-multiple). However I am not sure whether it will cause any problems for the model. Another solution would be enforcing the encoding of the table to utf8, in that way it can ensure the max key length is fixed no matter what encoding of the database used. To do this we need to change the migrations/0001_initial.py. # Change the construction of the table which ensure the character set of to UTF8. Require library sqlparse
operations = [
migrations.CreateModel(
name='KVStore',
fields=[
('key', models.CharField(serialize=False, db_column='key', max_length=10, primary_key=True)),
('value', models.TextField()),
],
),
migrations.RunSQL(
"ALTER TABLE `thumbnail_kvstore` CONVERT TO character\nSET utf8 COLLATE utf8_general_ci;"
),
migrations.AlterField(
model_name='KVStore',
name='key',
field=models.CharField(serialize=False, db_column='key', max_length=200, primary_key=True),
),
] However as the comment stated to do this the environment requires sqlparse library as the migrations.RunSQL needs the library in MySQL (See https://docs.djangoproject.com/en/1.10/ref/migration-operations/#runsql ). |
It's a bit late, but I also ran into this problem this week. My solution is make a database router. All tables sorl-thumbnail created stored in sqlite.
next is create a database router file
finally alter settings
and that's it |
Hello!
I am using the sorl-thumbnail v12.3 and mysql db in my django project.
And it raise mysql error (1071, 'Specified key was too long; max key length is 767 bytes') when migrate the sql. Because set the database`s collate with "utf8mb4_general_ci" .
Does somebady catch this problem? I just overwirte the max_length by this in models.py :
Does it has any other solution?
The text was updated successfully, but these errors were encountered: