「ActiveRecordをutf8mb4で動かす」をsqlite3併用環境でも動かす
ActiveRecordをutf8mb4で動かす
のinitializerが、開発環境とかでsqlite3みたいにMySQL以外のDBエンジンを併用している場合に上書き先のメソッドが未定義で死ぬので、NameError だけとっ捕まえるようにした。
ちなみに、SQLite3以外では未確認。問題無いとは思うけど。
config/initializers/ar_innodb_row_format.rb
ActiveSupport.on_load :active_record do
begin
module ActiveRecord::ConnectionAdapters
class AbstractMysqlAdapter < AbstractAdapter
def create_table_with_innodb_row_format(table_name, options = {})
table_options = options.reverse_merge(:options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC')
create_table_without_innodb_row_format(table_name, table_options) do |td|
yield td if block_given?
end
end
alias_method_chain :create_table, :innodb_row_format
end
end
rescue NameError => ex
# MySQLが使われていないので無視
end
end
Author And Source
この問題について(「ActiveRecordをutf8mb4で動かす」をsqlite3併用環境でも動かす), 我々は、より多くの情報をここで見つけました https://qiita.com/nekoruri/items/a91cc2654e2d0535f7b4著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .