新たに作ったテーブルにselectしたら以下のエラーになった。
1 |
ERROR 1267 (HY000): Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and ( utf8_general_ci,COERCIBLE) for operation '=' |
どうも、文字コードがおかしいようです。
テーブルの状態は以下でした。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
mysql> show create table schedules; +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |schedules | CREATE TABLE `schedules` ( `id` int(11) NOT NULL AUTO_INCREMENT, `place_id` int(11) DEFAULT NULL, `place_name` varchar(500) DEFAULT NULL, `category_id` tinyint(4) DEFAULT NULL, `schedule` varchar(500) DEFAULT NULL, `date` int(11) DEFAULT NULL, `year` smallint(6) DEFAULT NULL, `month` smallint(6) DEFAULT NULL, `day` smallint(6) DEFAULT NULL, `wday` tinyint(4) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
latin1がまずいのと思い、default charsetをutf8に。
1 |
mysql> alter table schedules default character set=utf8; |
結果以下の状態に。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
mysql> show create table schedules; +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | schedules | CREATE TABLE `schedules` ( `id` int(11) NOT NULL AUTO_INCREMENT, `place_id` int(11) DEFAULT NULL, `place_name` varchar(500) CHARACTER SET latin1 DEFAULT NULL, `category_id` tinyint(4) DEFAULT NULL, `schedule` varchar(500) CHARACTER SET latin1 DEFAULT NULL, `date` int(11) DEFAULT NULL, `year` smallint(6) DEFAULT NULL, `month` smallint(6) DEFAULT NULL, `day` smallint(6) DEFAULT NULL, `wday` tinyint(4) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
これでも、まだエラーになっていた、フィールドの文字コードがlatin1のままだからのようです。
なので、フィールドの文字コードも変更します。
1 2 |
mysql> alter table schedules modify place_name varchar(500) character set utf8; mysql> alter table schedules modify schedule varchar(500) character set utf8; |
これで、以下の状態となり、エラーがでなくなりました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
mysql> show create table stop_schedules; +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | stop_schedules | CREATE TABLE `stop_schedules` ( `id` int(11) NOT NULL AUTO_INCREMENT, `place_id` int(11) DEFAULT NULL, `place_name` varchar(500) DEFAULT NULL, `category_id` tinyint(4) DEFAULT NULL, `stop_schedule` varchar(500) DEFAULT NULL, `date` int(11) DEFAULT NULL, `year` smallint(6) DEFAULT NULL, `month` smallint(6) DEFAULT NULL, `day` smallint(6) DEFAULT NULL, `wday` tinyint(4) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |