Python 3.5.2
Django 2.0
Djangoでモデルをいじっているうちに下記エラーが出るようになった。
pymysql.err.InternalError: (1071, 'Specified key was too long; max key length is 767 bytes')
なぜだかrunserverではでない。testだけで発生する。
ググってみるとMySQLのエラーのようである。
innodb_large_prefixを使ってERROR 1071を回避する
対処方法としてMySQLのデータベース変更の方法がたくさん引っかかる。
ところで、なぜrunserverでは大丈夫で、testだとだめなのか。
どうやらモデルをいじっているうちにmigrationsファイルにそういう状態が記録されてしまっているからのようだ。
だとしたら、最新のmigrationsファイルでは問題ないのだから全部まとめてしまえばよいはず。
$ python ./manage.py squashmigrations app_label 最新のmigration_name
中略
Do you wish to proceed? [yN] y
Optimizing...
Optimized from 61 operations to 17 operations.
Created new squashed migration
まとめられた新しいmigration_name
You should commit this migration but leave the old ones in place;
the new migration will be used for new installs. Once you are sure
all instances of the codebase have applied the migrations you squashed,
you can delete them.
古いmigrationファイルはすべて消してtestすると無事終了した。