惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
C
Check Point Blog
V
V2EX
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
A
About on SuperTechFans
D
DataBreaches.Net
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
博客园_首页
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 幽谷清水

理解OAuth 2.0 IdentityServer4 中文文档 【转】ASP.NET Core 依赖注入 asp.net core部署到iis中出现 HTTP Error 502.5 - Process Failure的问题 在IIS上部署你的ASP.NET Core 2.1项目 AppBoxPro(权限管理框架--FineUIPro基础版+工厂模式+ADO.NET+存储过程) 阿里云 Windows Server 2012 r2 部署asp.net mvc网站 平坑之旅 tfs 禁止多人签出 Sql Server 向上取整、向下取整、四舍五入取整 微信WeixinJSBridge API Memcached+WebApi记录 iOS8自定义推送显示按钮及推送优化 支付宝友盟编译报错 控制器隐藏了导航 下页pop 导航位置看到黑条 安装Cocoapods xcode 插件 3.1 - Apps or metadata that mentions the name of any other mobile platform will be rejected 苹果电话、加急 火狐浏览器sqlite插件
ABP .Net Core Entity Framework迁移使用MySql数据库
幽谷清水 · 2018-07-05 · via 博客园 - 幽谷清水

一、迁移说明

ABP模板项目Entity Framework Core默认使用的是Sql Server,也很容易将数据库迁移到MySQL,步骤如下。

二、迁移MySQL步骤

1、 下载项目

请到 http://aspnetboilerplate.com/Templates 下载一个新的项目,选择ASP.NET Core 2.x标签,Target Framework:选中.Net Core就可以了。

2、 移除默认SQL Server相关包

在EntityFrameworkCore项目下移除包Microsoft.EntityFrameworkCore.SqlServer、Microsoft.EntityFrameworkCore.Design

 640?wx_fmt=png&wxfrom=5&wx_lazy=1

3、  添加MySql程序包

 添加程序包Pomelo.EntityFrameworkCore.MySql、Pomelo.EntityFrameworkCore.MySql.Design

 640?wx_fmt=png&wxfrom=5&wx_lazy=1

4、  修改源代码

修改DbContextConfigurer

public static class AbpBasicDbContextConfigurer

{

        public static void Configure(DbContextOptionsBuilder<AbpBasicDbContext> builder, string connectionString)

        {

            //builder.UseSqlServer(connectionString);

            builder.UseMySql(connectionString);

        }

        public static void Configure(DbContextOptionsBuilder<AbpBasicDbContext> builder, DbConnection connection)

        {

            //builder.UseSqlServer(connection);

            builder.UseMySql(connection);

        }

}

0?wx_fmt=png

5、  修改数据库链接字符串

在web项目配置文件appsettings.json

1

2

3

4

"ConnectionStrings": {

    //"Default": "Server=localhost; Database=AbpBasicDb; Trusted_Connection=True;"

    "Default": "Server=localhost; port=3306; Database=AbpBasicDb; uid=root; pwd=****; Convert Zero Datetime=True"

}

 0?wx_fmt=png

6、  数据迁移

重新生成迁移文件

在下载启动模板的时候,如果你选择了包含 Module Zero。这里会有一些迁移文件会包含在你的项目中,但是这些文件是为Sql Server迁移使用的。请打开 .EntityFramework 项目中的Migrations文件夹,然后删除这些迁移文件。迁移文件是以时间戳开始的。迁移文件的名字像这样:201506210746108_AbpZero_Initial。

0?wx_fmt=png

在删除所有的迁移文件后,选择你的 .Web 项目为开始项目,打开VS的包管理控制台,并在包管理控制台中选择 .EntityFramework 项目作为默认项目。然后在控制台中执行下面命令:

Add-Migration "AbpZero_Initial"

0?wx_fmt=png

现在你可以使用下面命令来创建数据库:

Update-Database

0?wx_fmt=png

所有的事情都已完成,检查 MySQL数据库已生产成功

 0?wx_fmt=png

7、  完成MySQL迁移后运行浏览成功

 0?wx_fmt=png

原文地址:https://www.cnblogs.com/donaldtdz/p/8149598.html

-------------------------------------------------------------------------------------------------------------------------------

使用ABP框架进行First Code时,出现错误如下:

Your startup project 'HHTime.Core' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

出错原因是因为启动项没有选择Migrator,默认启动项是core,修改启动项为Project.Migrator即可

---------------------------------------------------------------------------------------------------------------------------------------

System.MissingMethodException: Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder..ctor(Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper)'.
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlCommandBuilder..ctor(IDiagnosticsLogger`1 logger, IRelationalTypeMapper typeMapper)
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlCommandBuilderFactory.CreateCore(IDiagnosticsLogger`1 logger, IRelationalTypeMapper relationalTypeMapper)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommandListBuilder..ctor(IRelationalCommandBuilderFactory commandBuilderFactory)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList`1 operations, IModel model)
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlDatabaseCreator.Create()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder..ctor(Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper)'.

解决方案:

 编辑项目.csproj文件,在<ItemGroup>配置加入

<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.0-rc1-final" />