How to make a Rails Migration be utf-8 instead of my default latin1

GeekedOut picture GeekedOut · May 24, 2011 · Viewed 8k times · Source

I just checked my MySQL tables and I have default set as latin1. Is that generally the default?

How can I make it explicit for all my tables that I want the database to be utf-8?

I know there is a db configuration that can change the default, but I think there is also a way to do it per-migration. How could I permanently set my rails migrations from now on to be utf-8?

Thanks!

Answer

Olivier L. picture Olivier L. · May 24, 2011

create_table(:table_name, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8')