Home utf8mb4 character set for Rails application
Reply: 0

utf8mb4 character set for Rails application

user1266
1#
user1266 Published in April 20, 2018, 10:48 am

I am using MySQL version 5.7.12; I am trying to add emoji support in a text field. I found this article. It states to alter the table and column to enable utf8mb4, which supports true unicode, including 4 byte unicode characters. I have a table comments and text field content, so I perform the following operation:

class ConvertCommentsToUtf8mb4 < ActiveRecord::Migration
  def change
    # for each table that will store unicode execute:
    execute "ALTER TABLE comments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"
    # for each string/text column with unicode content execute:
    execute "ALTER TABLE comments CHANGE content TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"
  end
end

When I try to run a migration, I get the following error:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET utf8mb4 COLLATE utf8mb4_bin' at line 1: ALTER TABLE comments CHANGE content TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin/Users/myuser/.rvm/gems/ruby-2.1.2@core/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `_query'

What might I be doing wrong?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.439695 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO