6

Is it possible to change the charset and collation of an existing Mysql database using Rails migrations or other options ?!

What's the best way to initially configure database charset & collation ?!

1 Answer 1

8

Native query could be executed in rails migration:

def self.up
  execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET charset_here COLLATE collation_here;"
end

And for initial configuration you can predefine charset and collation in your database.yml file, like this:

production:
  adapter: mysql2
  encoding: utf8mb4
  collation: utf8mb4_unicode_ci

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.