Recently I upgraded MySQL to 5.7.10 and realised that I cannot run new model migrations on my old Rails 3 project anymore:
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `bot_users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `bot_type` int(11) DEFAULT 1, `user_id` varchar(255), `first_name` varchar(255), `last_name` varchar(255), `username` varchar(255), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL)
It appears that MySQL version 5.7 and more doesnt support NULL default anymore so I need a workaround –
create initializer `config/initializers/mysql2_adapter.rb` that has following contents:
class ActiveRecord::ConnectionAdapters::Mysql2Adapter NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY" end
After that migration runs fine.