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

1

12

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!

Tieck answered 23/5, 2011 at 23:16 Comment(0)
P
21

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

Pancreatin answered 23/5, 2011 at 23:23 Comment(1)
Alternatively, you can set default-storage-engine = InnoDB in your my.cnf for MySQL. You can also set MySQL's default character set and collation to utf8. There are a lot of options here, so you'll want to dive into the docs for more info on that: dev.mysql.com/doc/refman/5.0/en/server-system-variables.htmlCruickshank

© 2022 - 2024 — McMap. All rights reserved.