Help us understand the problem. What is going on with this article?

MySQLでpecified key was too longとエラーが出た

More than 1 year has passed since last update.

CREATE TABLEしたら、なんかエラーが出た。

ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

どのカラムがダメなのか何もエラーメッセージに含まれていない。大人は質問に答えたりしないそうです。

理由

私の場合はユニークキー制約をつけたVARCHARカラムが問題でした。

access_token VARCHAR(256) UNIQUE NOT NULL

256文字を指定していますが、ASCII文字以外を許可しているため767バイト以上になりうるため怒られているのです。アクセストークンのようなものは、1文字1バイトのASCII文字列だけで良いので、このようにしたらエラーは消えました。

access_token VARCHAR(256) CHARACTER SET ascii UNIQUE NOT NULL
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away