0

I am using Devise with rails 4 and ruby 2.0 and database is MySQL Ver 14.14 Distrib 5.5.38. When a user sign up with names like "Мукеш"(Russian for Mukesh), I get an error as below

Mysql2::Error: Incorrect string value

I tried editing the database through MySQL Workbench and it is working, but rails is showing question marks when displaying that data.

How can I tell the ORM/Rails/Devise to accept Unicode characters? Please let me know if more details are needed

Thanks in advance,

mukesh
  • 127
  • 1
  • 9
  • DId you try adding encoding to database.yml `encoding: utf8` – mintuhouse Sep 23 '14 at 11:40
  • Also try adding `config.encoding = "utf-8"` to your application.rb – mintuhouse Sep 23 '14 at 11:42
  • I have utf8 encoding in database.yml. What encoding should I specify? – mukesh Sep 23 '14 at 11:42
  • one more thing, MySQL workbench didn't give any errors, but the the data there is shown as "????". Does this mean my MySQL config is not set to accept unicode characters?? – mukesh Sep 23 '14 at 11:43
  • `SHOW VARIABLES LIKE 'character\_set\_%';` Find your default encoding & change it to utf-8 if it is not already so. Only disadvantage would be that you would loose mysql 5.6 full text search, which I guess you may not need on users table – mintuhouse Sep 23 '14 at 11:46
  • http://stackoverflow.com/questions/6115612/how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8 – mintuhouse Sep 23 '14 at 11:47
  • @mintuhouse tried adding encoding inside `class Application < Rails::Application` as you specified, but still getting the same error – mukesh Sep 23 '14 at 11:48
  • Did changing mysql collation type work? – mintuhouse Sep 23 '14 at 11:55
  • did this `USE test_db; ALTER TABLE users DEFAULT CHARACTER SET utf8;` but not working – mukesh Sep 23 '14 at 12:03

1 Answers1

0

This is an issue with MySQL database column. Enlightened by @minthouse's words, I changed the encoding of the name column, instead of the entire table.

ALTER TABLE users MODIFY name VARCHAR(50) CHARACTER SET utf8;

Thanks @minthouse for your help

mukesh
  • 127
  • 1
  • 9