I have a migration in rails that does the following:
class AddMissingIndexes < ActiveRecord::Migration[5.1]
def change
# Applications
add_index :applications, :evid, length: { evid: 255 }
end
end
This seems to run smoothly in my test environment
However when I run the migration in my production environment I get this error:
Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE INDEX `index_applications_on_evid` ON `applications` (`evid`(255))
I'm trying to fix this issue using the second answer from this question
class AddMissingIndexes < ActiveRecord::Migration[5.1]
def change
# Applications
add_index "applications", ["evid"], :name => :evid, :length => { :evid => 255 }
end
end
However I want to make sure this works before making any further changes to the schema. So I need to be able to reproduce this error in my test environment.
Test environment:
+-------------------------+------------------+
| Variable_name | Value |
+-------------------------+------------------+
| innodb_version | 5.5.62 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.5.62-0+deb8u1 |
| version_comment | (Debian) |
| version_compile_machine | x86_64 |
| version_compile_os | debian-linux-gnu |
+-------------------------+------------------+
Production environment
+-------------------------+---------------------+
| Variable_name | Value |
+-------------------------+---------------------+
| innodb_version | 5.6.40 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.6.40-log |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
+-------------------------+---------------------+
Using SHOW GLOBAL VARIABLES LIKE 'innodb_%';
I'm able to see my test environment database and this is what I found that my local db environment has the following variables like this:
Test Environment
innodb_file_format=Barracuda;
innodb_large_prefix=1;
innodb_file_per_table=1;
innodb_file_format_max=Barracuda;
innodb_strict_mode=1;
character_set_server='utf8mb4';
Production Environment
innodb_file_format=Antelope;
innodb_large_prefix=OFF;
innodb_file_per_table=ON;
innodb_file_format_max=Antelope;
innodb_strict_mode=OFF;
character_set_server='utf8mb4';
I tried to reproduce my production environment setting the variables going 1 at a time. But to no avail.