python
$ docker -v
Docker version 19.03.12
$ rails -v
Rails 6.0.3.2
$ mysql --version
mysql Ver 14.14 Distrib 5.7.29, for osx10.15 (x86_64) using EditLine wrapper
error contents
ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value: '\xE3\x83\x8F\xE3\x83\xAA...' for column 'name' at row 1):
Oh, it seems that it is not recognized as Japanese Do you want to check the settings by looking at the charaset of the database?
python
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f51c4b953b05 feeder-in_back "rails server -b 0.0…" About an hour ago Up About an hour 0.0.0.0:3000->3000/tcp back
925b28f3b58d mysql:5.7 "docker-entrypoint.s…" About an hour ago Up About an hour 33060/tcp, 0.0.0.0:3308->3306/tcp database
ab6efeba59a1 feeder-in_web "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:8080->3000/tcp web
$ docker exec -it 925b28f3b58d mysql -u root -p
mysql> show variables like "chara%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.03 sec)
character_set_database | latin1
As far as I can see, it is the default charaset of MySQL, and it does not support Japanese.
docker-compose.yml
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
python
$ docker-compose down
$ docker-compose up -d --build
database.yml
default: &default
charset: utf8mb4 #Postscript
encoding: utf8mb4
python
$ docker-compose exec back sh
> rake db:drop
> rake db:create
> rails db:migrate
Now you have a database that supports Japanese!
Recommended Posts