I’d like to change an existing MySQL column from VARCHAR to VARCHAR BINARY in order to change it to be case-sensitive (see: https://stackoverflow.com/a/3396315/93995)
What’s the proper migration syntax for this? I tried
change_column :my_table, :my_column, :binary, :limit => 255
but that tries to change it to a blob(255). Also complains:
Mysql2::Error: BLOB/TEXT column 'my_column' used in key specification without a key length: ALTER TABLE `my_table` CHANGE `my_column` `my_column` blob(255) DEFAULT NULL
To change a single column to be case sensitive, you’ll need to use SQL DDL directly to change to the collation to ‘utf8_bin’:
Note that this is still using the ‘varchar’ type as storage, only the collation (interpreted meaning) is defined as ‘binary’ for comparison purposes. Also note that you may not be able to compare columns with different collations, so make sure this is what you really want.
If you wanted to make a whole table use a specific collation, that can easily be done: