关于如何使用请查看项目文档便可
组件地址:https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySqlmysql
遇到的是在使用 CodeFirst 生成数据库的字符集编码问题
执行迁移命令:Add-Migration 版本
, Update-Database
生成数据库(若无自动建立)的字符集为 latin1 -- cp1252 West European
此字符集将会在生成查询语句包含中文的时候报以下错误git
Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_bin,COERCIBLE) for operation '='MySql.Data.MySqlClient.MySqlException (0x80004005): Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_bin,COERCIBLE) for operation '=' ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_bin,COERCIBLE) for operation '='
其实组件最开始就建议了设置字符集为:utf8mb4
(MySQL5.5.3及以上),因此遇到上诉错误只须要执行修改数据库字符集命令便可github
utf8mb4
的数据库再执行迁移alter database 数据库名称 character set utf8mb4;
,可是注意这并不能修改已建立的表的字符集编码;故仍是建议手动建立数据库。show variables like 'character_set_database';
alter database 数据库名称 character set utf8mb4;