MENU

railsでROW_FORMAT=COMPRESSEDのオプションがついてるmigrationでこけた場合の対処

# エラーが出る
$ rails db:migrate
Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Table storage engine for 'table' doesn't have this option: CREATE TABLE `table` (`id` bigint unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, `id` varchar(255) NOT NULL, `type` varchar(255) NOT NULL, `point` int NOT NULL, `after_point` int NOT NULL, `hoge_type` varchar(255) NOT NULL, `hoge_json` text, `created_at` datetime, `updated_at` datetime) ROW_FORMAT=COMPRESSED : 

# dbの設定を確認する
mysql> show variables like "innodb_file%";
+--------------------------+-----------+
| Variable_name            | Value     |
+--------------------------+-----------+
| innodb_file_format       | Barracuda |
| innodb_file_format_check | ON        |
| innodb_file_format_max   | Barracuda |
| innodb_file_per_table    | OFF       |
+--------------------------+-----------+
4 rows in set (0.00 sec)

# innodb_file_per_tableをONにしたい。
mysql> SET GLOBAL innodb_file_per_table=1;

# ONになっている
mysql> show variables like "innodb_file%";
+--------------------------+-----------+
| Variable_name            | Value     |
+--------------------------+-----------+
| innodb_file_format       | Barracuda |
| innodb_file_format_check | ON        |
| innodb_file_format_max   | Barracuda |
| innodb_file_per_table    | ON        |
+--------------------------+-----------+
4 rows in set (0.00 sec)

$ rails db:migrate
=>ROW_FORMAT=COMPRESSEDのオプションがついていても通る。

参考:https://dev.mysql.com/doc/refman/5.6/ja/tablespace-enabling.html