Activerecord::statementinvalid (Mysql2::error:incorrect String value:

Source: Internet
Author: User

There's a pretty tricky question today, and that's Activerecord::statementinvalid (Mysql2::error:incorrect string value.

There is no problem with the local test, but one to the server will be error, the error is: Mysql2::error:incorrect string value, after analysis found to be the problem of Chinese. According to theory, there has been no such situation before, why this time there is a problem? Check it out, nothing strange. So the local hit the same environment, and then the test is still no problem. This is difficult to die, because every time the test, the log on the server is the same, as long as the Chinese will be wrong. Helpless only to log on to the server to modify the configuration.

First look at the charset of the database:

Show variables like '%char% '

The discovery database on the charset server is the type of Latin, and thus changed to UTF8, this to modify the configuration file, the modification after the restart, found that CharSet did change, but still error. To check the internet, and said rails4.0 problems, and back to the problem of MySQL. But the feeling is not similar to my situation. What to do? Suddenly think of a few days ago as Django encountered a problem, and then think of whether it is collation problem. So I looked at it.

Show Table Status

If you find the problem, it is the problem of collations. The following is the collation of the database and table, providing a stupid way:

ALTER database name of DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci

Each of these two data tables is executed once.  the name of the ALTER table table is DEFAULT CHARACTER SET UTF8; ALTER table   name CONVERT to CHARACTER SET UTF8;

StackOverflow solutions are similar:
ALTER TABLE `[table]` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,MODIFY [column] VARCHAR(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin
then perform the migration

Activerecord::statementinvalid (Mysql2::error:incorrect String value:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.