いい感じにまとまってるページがなかったのでまとめておきます。
Mysql(MariaDB)の対応
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix
Railsの対応
-
config/initialize
に追加
# config/initializers/ar_innodb_row_format.rb
ActiveSupport.on_load :active_record do
module ActiveRecord::ConnectionAdapters
module CreateTableWithInnodbRowFormat
def create_table(table_name, options = {})
table_options = options.merge(options: 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC')
super(table_name, table_options) do |td|
yield td if block_given?
end
end
end
class AbstractMysqlAdapter
prepend CreateTableWithInnodbRowFormat
end
end
end
- database.ymlを修正
# config/database.yml
default: &default
adapter: mysql2
encoding: utf8mb4
charset: utf8mb4
collation: utf8mb4_general_ci