How to make Rails ActiveRecord::Migration default to MyISAM

Some people perfer InnoDB, other MyISAM. This post ain't about a MySQL-Engine flame war but about letting people choice. Fact is, the excellent Migration system shipped with [rubyonrails]( and ActiveRecord is defaulting to InnoDB. The [doc]( shows how you can specify the engine on each create_table statement. but then your migration are mysql-only because these engine options will not be supported by sqlite or MSSQL. and I dont want to copy/paste these options to all of my create table. I want to change the default. unfortunately Rails supply no options for it fortunately Rails is built on Ruby. so you can simply overwrite the proper method by adding it to your config/environment.rb
module ActiveRecord
        module ConnectionAdapters
                class MysqlAdapter < AbstractAdapter
                        def create_table(table_name, options = {}) #:nodoc:
                                super(table_name, options.reverse_merge(:options => "ENGINE=MyISAM"))

Tags , , , , , , , , ,

Posted in , , | Posted on 08 Apr 2009 13:56by somekool |


my last twitter posts

Personal Links




my Xbox 360 gamertag

Copyright © Mathieu Jobin's Life and Thoughts