mysql2 icon indicating copy to clipboard operation
mysql2 copied to clipboard

Mysql2::Error: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb3_general_ci,COERCIBLE)

Open mices opened this issue 3 years ago • 3 comments

error: Mysql2::Error: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb3_general_ci,COERCIBLE) for operation '=' (ActiveRecord::StatementInvalid)

table structure: create_table "sms", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "contact" t.datetime "time_stamp", precision: nil t.string "sent_received" t.text "body", size: :medium, null: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.string "time_stamp_long" end

script running in rails console using load command: file=File.open('sms-20210602101134.xml') doc=Nokogiri::XML.parse(file) doc.xpath('//sms').each do |msg| Sms.find_or_create_by(contact: msg['address'], time_stamp: msg['date'], sent_received: msg['type'], body: msg['body']) end

mices avatar Dec 13 '22 00:12 mices

You've set a specific charset and collation on the table, also set a matching charset and collation on the connection to the database.

sodabrew avatar Dec 16 '22 17:12 sodabrew

How would I do that in rails console? The connection to the database is only made with Sms.find_or_create_by ... where Sms is the model name Also for some reason I have to use Sm instead of Sms, must be a reserved name

On Fri, Dec 16, 2022 at 12:07 PM Aaron Stone @.***> wrote:

This error means that you need to set a compatible collation in your connection string with the one you have set on the database itself.

— Reply to this email directly, view it on GitHub https://github.com/brianmario/mysql2/issues/1287#issuecomment-1355230234, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADPZ3EQYCRIBH3RMP6JRATLWNSOVXANCNFSM6AAAAAAS4SY6XI . You are receiving this because you authored the thread.Message ID: @.***>

mices avatar Dec 16 '22 17:12 mices

I supposed there's a collation setting I can use in database.yml I'll check Thanks

On Fri, Dec 16, 2022 at 12:07 PM Aaron Stone @.***> wrote:

This error means that you need to set a compatible collation in your connection string with the one you have set on the database itself.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

mices avatar Dec 16 '22 17:12 mices