1.使用mysql 首先要确定mysql connector 支的版本,正面是链接

https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework-core.html

Table 9.2 Supported versions of Entity Framework Core

Connector/NET EF Core 1.1 EF Core 2.0 EF Core 2.1
6.10.4 .NET Standard 1.3 or .NET Framework 4.5.2 (and later) Not supported Not supported
6.10.5 to 6.10.7 .NET Standard 1.3 or .NET Framework 4.5.2 (and later) .NET Standard 2.0 only (.NET Framework is not supported)

Scaffolding is not supported

Not supported
6.10.8 .NET Standard 1.3 or .NET Framework 4.5.2 .NET Standard 2.0 or .NET Framework 4.6.1 (and later) Not supported
8.0.11 to 8.0.12 .NET Standard 1.6 or .NET Framework 4.5.2 (and later) .NET Standard 2.0 only (.NET Framework is not supported)

Scaffolding is not supported

Not supported
8.0.13 .NET Standard 1.6 or .NET Framework 4.5.2 Not supported .NET Standard 2.0 or .NET Framework 4.6.1 (and later)

2.配置数据库连接字符串

{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebMvc-6350BA27-C046-416F-B717-F8342091E6E4;Trusted_Connection=True;MultipleActiveResultSets=true",
"MysqlConnection": "server=localhost;database=mydb;uid=root;pwd=123456;" },
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}

3 修改StartUP

  public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySQL(Configuration.GetConnectionString("MysqlConnection"))); services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders(); // Add application services.
services.AddTransient<IEmailSender, EmailSender>(); services.AddMvc();
}

4 生成Migration ,数据迁移过程中有一个bug就是原生 clr bool类型为强转成short类型,如果要程序不报错需要做一个强制转换,在使用Add-Migration InitialCreate  方法对生成的代码需要加以下注释

// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WebMvc.Data; namespace WebMvc.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20181210165422_Update")]
partial class Update
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687"); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd().HasMaxLength(50); b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken(); b.Property<string>("Name")
.HasMaxLength(256); b.Property<string>("NormalizedName")
.HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex"); b.ToTable("AspNetRoles");
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd().HasMaxLength(50); b.Property<string>("ClaimType"); b.Property<string>("ClaimValue"); b.Property<string>("RoleId")
.IsRequired().HasMaxLength(50); b.HasKey("Id"); b.HasIndex("RoleId"); b.ToTable("AspNetRoleClaims");
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd().HasMaxLength(50); b.Property<string>("ClaimType"); b.Property<string>("ClaimValue"); b.Property<string>("UserId")
.IsRequired(); b.HasKey("Id"); b.HasIndex("UserId"); b.ToTable("AspNetUserClaims");
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider").HasMaxLength(50); b.Property<string>("ProviderKey").HasMaxLength(50); b.Property<string>("ProviderDisplayName"); b.Property<string>("UserId")
.IsRequired(); b.HasKey("LoginProvider", "ProviderKey"); b.HasIndex("UserId"); b.ToTable("AspNetUserLogins");
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId").HasMaxLength(50); b.Property<string>("RoleId").HasMaxLength(50); b.HasKey("UserId", "RoleId"); b.HasIndex("RoleId"); b.ToTable("AspNetUserRoles");
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId").HasMaxLength(50); b.Property<string>("LoginProvider").HasMaxLength(50); b.Property<string>("Name").HasMaxLength(50); b.Property<string>("Value"); b.HasKey("UserId", "LoginProvider", "Name"); b.ToTable("AspNetUserTokens");
}); modelBuilder.Entity("WebMvc.Models.ApplicationUser", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd(); b.Property<int>("AccessFailedCount"); b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken(); b.Property<string>("Email")
.HasMaxLength(256); b.Property<short>("EmailConfirmed")
.HasColumnType("bit"); b.Property<short>("LockoutEnabled")
.HasColumnType("bit"); b.Property<DateTimeOffset?>("LockoutEnd"); b.Property<string>("NormalizedEmail")
.HasMaxLength(256); b.Property<string>("NormalizedUserName")
.HasMaxLength(256); b.Property<string>("PasswordHash"); b.Property<string>("PhoneNumber"); b.Property<short>("PhoneNumberConfirmed")
.HasColumnType("bit"); b.Property<string>("SecurityStamp"); b.Property<short>("TwoFactorEnabled")
.HasColumnType("bit"); b.Property<string>("UserName")
.HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedEmail")
.HasName("EmailIndex"); b.HasIndex("NormalizedUserName")
.IsUnique()
.HasName("UserNameIndex"); b.ToTable("AspNetUsers");
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("WebMvc.Models.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("WebMvc.Models.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade); b.HasOne("WebMvc.Models.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
}); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("WebMvc.Models.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade); });
#pragma warning restore 612, 618
}
}
}

源码下载

github

Microsoft.AspNetCore.Identity 使用 mysql 报错处理的更多相关文章

  1. 使用Mybatis连接到Mysql报错,WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be esta

    在Eclipse中使用springboot整合Mybatis,连接到5.7版本Mysql报错WARN: Establishing SSL connection without server's ide ...

  2. PHP连接MySQL报错:SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket 'MySQL' (2)

    如下所示,PHP连接MySQL报错: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket 'MySQL' ...

  3. Asp.Net连接Mysql报错Out of sync with server

    Asp.Net连接Mysql报错Out of sync with server 原因:程序引用的MySql.Data.dll版本高于服务器版本 解决:下载一个低版本的MySql.Data.dll,项目 ...

  4. Linux系统下启动MySQL报错:Neither host &#39;localhost.localdomain&#39; nor &#39;localhost&#39; could be looked up with

    Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with 摘要 Li ...

  5. 启动Mysql报错:Another MySQL daemon already running with the same unix socket.

    启动Mysql报错: Another MySQL daemon already running with the same unix socket. 删除如下文件即可解决 /var/lib/mysql ...

  6. Mysql报错注入原理分析(count()、rand()、group by)

    Mysql报错注入原理分析(count().rand().group by) 0x00 疑问 一直在用mysql数据库报错注入方法,但为何会报错? 百度谷歌知乎了一番,发现大家都是把官网的结论发一下截 ...

  7. 解决:MySQL 报错:1045 - Access denied for user 'root'@'localhost'(using password YES)

    一.前言 今年疯狂迷上了开源,只要看到好的开源项目,就会不顾一切一股脑扎进去研究,五一期间发现一个很好的关于众筹的开源项目,但不巧,这个项目竟然是 PHP 写的,没学过 PHP,自然对这个开源项目毫无 ...

  8. 开启bin-log日志mysql报错:This function has none of DETERMINISTIC, NO SQL解决办法

    开启bin-log日志mysql报错:This function has none of DETERMINISTIC, NO SQL解决办法: 创建存储过程时 出错信息: ERROR 1418 (HY ...

  9. InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]'

    在新建asp.net core 应用后, 添加了自定义的ApplicationDbContext 和ApplicationUser ,并添加了Identity认证后, 会出现 InvalidOpera ...

随机推荐

  1. AC日记——Milking Grid poj 2185

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8314   Accepted: 3586 Desc ...

  2. Codeforces 471 D MUH and Cube Walls

    题目大意 Description 给你一个字符集合,你从其中找出一些字符串出来. 希望你找出来的这些字符串的最长公共前缀*字符串的总个数最大化. Input 第一行给出数字N.N在[2,1000000 ...

  3. hadoop之hdfs------------------FileSystem及其源码分析

    FileSystem及其源码分析 FileSystem这个抽象类提供了丰富的方法用于对文件系统的操作,包括上传.下载.删除.创建等.这里多说的文件系统通常指的是HDFS(DistributedFile ...

  4. Jackson对泛型的序列化和反序列化方法汇总

    说明:Jackson对于简单泛型是可以正常操作的,但是如果对于太过于复杂的泛型类有时会不成功.目前还在找着更合适的Json库.不过这一点在dotnet原生方案JavaScriptSerializer可 ...

  5. jquery 全选获取值

    首选区分一下prop与attr的差别.prop是固有属性,attr自定义属性. $("#all").click(function () {//全选.反选 if(this.check ...

  6. Node之父ry发布新项目deno:下一代Node

    https://mp.weixin.qq.com/s/1LcO3EqGV2iRlZ1aIrQeqw

  7. TCP通过滑动窗口和拥塞窗口实现限流,能抵御ddos攻击吗

    tcp可以通过滑动窗口和拥塞算法实现流量控制,限制上行和下行的流量,但是却不能抵御ddos攻击. 限流只是限制访问流量的大小,是无法区分正常流量和异常攻击流量的. 限流可以控制本软件或者应用的流量大小 ...

  8. 实现TextView中link的点击效果

    朋友们,你们在TextView处理link的时候是不是一直被苦逼的android默认的方式困扰?每次点击link的时候,点击效果是整个textview来响应.非常烂吧?原因就不多赘述了. 那么以下这个 ...

  9. NAT和桥接的区别

    NAT 桥接 NAT相当于是局域网中的局域网,把192.168.21.1当作外网ip,重新划分了一个网关(192.168.33.x) 网桥只是把网络桥接起来,还是原来的网关(192.168.21.x) ...

  10. 发送验证码60s倒计时实现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...