Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my table's encoding wrong?

I'm using Rails 5 and MySQL 5.7. I have the following in my database.yml:

default: &default
  adapter: mysql2
  pool: 5
  encoding: utf8mb4
  charset: utf8mb4
  collation: utf8mb4_unicode_ci
  socket: /tmp/mysql.sock

development:
  <<: *default
  database: [...]
  username: [...]
  password: [...]

I run rake db:reset to recreate my database and I run show create table users and I see CREATE TABLEusers([...]) ENGINE=InnoDB DEFAULT CHARSET=utf8.

Why does my CHARSET=utf8 and how can I fix it (make it equal utf8mb4)? Thanks.

like image 306
nc. Avatar asked Sep 13 '26 07:09

nc.


1 Answers

rake db:reset is wrong. rake db:drop && rake db:create && rake db:migrate is correct.

The reset just created the tables from the already stored schema which had the wrong charset and collation. But re-creating them from the migrations created them with the new charset and collation.

like image 89
nc. Avatar answered Sep 15 '26 22:09

nc.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!