-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
emoji encoding issue with mysql adapter #11184
Comments
It looks like this could be caused by this MySQL issue. You could maybe try the suggestion in the answer for a temporary fix. These questions also look like they may have a fix. If it's supported in Rails 4, setting the encoding to utf8mb4 seems like it should work. As far as ActiveRecord goes, it looks like it uses the same default charset (utf8) in both 3.2.13 and 4.0.0, so I still haven't found what is causing the issue. They also use the same default collation (utf8_unicode_ci). It looks like the bug is with MySQL itself, but that doesn't explain it working correctly for ActiveRecord 3.2.13. I wasn't able to test with 3.2.13 because I hope some of this helps! |
@ryan-endacott , thanks for taking the time to investigate. I agree that the root of the problem is in fact a MySQL issue, specifically that their utf8 encoding seems to not entirely support utf8. As this commenter explains, you cannot store characters that are outside the Basic Multilingual Plane using only 3 bytes as MySQL does. I was a bit mystified as to how it was working under 3.2.13 but not 4.0.0. Fleshing out my test a bit more I find that The path forward here seems to be using the 'utf8mb4' encoding along with 'utf8mb4_unicode_ci' collation. Rails4 seems to support this, but unfortunately the latest released mysql2 gem does not. There's a nice writeup here on how to use the git head version of mysql2 to make that work. Either that or I will bite the bullet and finally move all my apps to Postgres. :-) |
@armhold, I was also mystified at it seemingly working for 3.2.13! I'm glad you figured it out. It looks like it no longer silently truncates the data because of this change in the release notes:
|
Hi,
I ran into this while migrating an app from Rails 3 to 4. It seems that some unicode escaped strings (Emoji specifically) cause an
ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect string value
error.Here's a gist: https://gist.github.com/armhold/5892370
Does not seem to be an issue when using the sqlite adapter, so you will have to set up a MySQL instance (sorry!) to demonstrate. I'm using mysql-5.5.23-osx10.6-x86_64.
If you run it against activerecord 3.2.13 it works fine.
Thanks for investigating.
The text was updated successfully, but these errors were encountered: