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. 海量端口扫描工具masscan

    海量端口扫描工具masscan   masscan号称是互联网上最快的端口扫描工具,可以6分钟扫描整个互联网,每秒可以发送一百万个数据包.为了提高处理速度,masscan定制了TCP/IP栈,从而不影 ...

  2. HDU 3534 Tree (经典树形dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3534 题意: 给你一棵树,问你有多少对点的距离等于树的直径. 思路: dp[i][0]表示在i的子树中 ...

  3. BZOJ3270 博物館 概率DP 高斯消元

    BZOJ3270 博物館 概率DP 高斯消元 @(XSY)[概率DP, 高斯消元] Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博 ...

  4. JS中原型链中的prototype与_proto_的个人理解与详细总结(**************************************************************)

    一直认为原型链太过复杂,尤其看过某图后被绕晕了一整子,今天清理硬盘空间(渣电脑),偶然又看到这图,勾起了点回忆,于是索性复习一下原型链相关的内容,表达能力欠缺逻辑混乱别见怪(为了防止新人__(此处指我 ...

  5. UIAlertView弹出视图动画效果

    在App设计中为了加强用户体验,我们会常常加入一些友好的动画效果.比如类似UIAlertView弹出的动画效果,由于系统中并没有直接提供类似的动画API,如果我们想要做出一样的效果,那就得深入的研究一 ...

  6. 进程间通信IPC、LPC、RPC

    进程间通信(IPC,Inter-Process Communication),指至少两个进程或线程间传送数据或信号的一些技术或方法.进程是计算机系统分配资源的最小单位.每个进程都有自己的一部分独立的系 ...

  7. Android应用开发之所有动画使用详解

    题外话:有段时间没有更新博客了,这篇文章也是之前写了一半一直放在草稿箱,今天抽空把剩余的补上的.消失的这段时间真的好忙,节奏一下子有些适应不过来,早晨七点四十就得醒来,晚上九点四十才准备下班,好像最近 ...

  8. sublime text 3和sublime text 2的 package control 插件 代码

    SECURITY NOTICE: The Python code used by this method does not use SSL because Sublime Text on Linux ...

  9. 学会用core dump调试程序错误

    最来在项目中遇到大型程序出现SIGSEGV ,一直不知道用core dump工具来调试程序,花了近一周的时间,才定位问题,老大很生气,后果很严重,呵呵,事后仔细学习了这块的知识,了解一点core du ...

  10. 【windows socket+UDPserverclient】

    Windows Socket+UDPserverclient      Winsock是 Windows下套接字标准.                    1.UDP socket编程:       ...