ABP使用Mysql数据库

1.在.EntityFramework和.Web中安装 MySql.Data.Entity; 
2.打开SbContext的配置类(Configuration.cs),在该类的构造函数添加下面代码
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
3.配置连接字符串
<add name="Default" connectionString="server=localhost;port=3306;database=sampledb;uid=root;password=***" providerName="MySql.Data.MySqlClient"/>
4.删除所有的迁移文件,重新生成迁移文件并更新
> Add-Migration dev1
> Update-Database


特别注意:
1.使用MySql.Data.Entity6.10.x, Add-Migration dev1的时候会报如下错误:
Inheritance security rules violated by type: 'System.Web.Mvc.MvcWebRazorHostFactory'. Derived types must either match the security accessibility of the base type or be less accessible.
出现上面问题的解决办法:
降低MySql.Data.Entity的版本即可, 6.9.10是没有问题的。
2.update-database出现这个问题   Specified key was too long; max key length is 767 bytes
解决办法:在DbContext上添加[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
3.Unknown storage engine 'InnoDb'   这是mysql默认引擎未开启InnoDb导致的
解决办法:需要修改mysql的相关配置
有两种解决方法:
        方法一.修改my.ini文件,把skip-innodb这行注释掉
        方法二.修改my.ini文件,default-storage-engine=InnoDb

猜你喜欢

转载自blog.csdn.net/bingtome/article/details/79015526