Mysql::Error: Specified key was too long; max key length is 767 bytes: CREATE INDEX

It sounds like the default collation uses the UTF8 character set.

MySQL limits the length of keys by bytes, not characters. Since the UTF8 implementation MySQL uses allows for 3 bytes per character, the max length of a key on a UTF8 column is 3 times the key length in characters (the key length is the full length of the field if not explicitly specified).

In this case the max key length would be 256 * 3 which is 768. You need to either limit the length of the key or change the collation of the column.


how about changing the migration itself:

remove_index "bookings", :name => :trip_cities
add_index "bookings", ["trip_cities"], :name => :trip_cities, :length => { :trip_cities => 255 }

You should recreate your database with correct options.

This helped to me with same problem

CREATE DATABASE ${DB} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;