Microsoft.AspNetCore.Identity 使用 mysql 报错处理
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
}
}
}
源码下载
Microsoft.AspNetCore.Identity 使用 mysql 报错处理的更多相关文章
- 使用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 ...
- 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' ...
- Asp.Net连接Mysql报错Out of sync with server
Asp.Net连接Mysql报错Out of sync with server 原因:程序引用的MySql.Data.dll版本高于服务器版本 解决:下载一个低版本的MySql.Data.dll,项目 ...
- Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with
Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with 摘要 Li ...
- 启动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 ...
- Mysql报错注入原理分析(count()、rand()、group by)
Mysql报错注入原理分析(count().rand().group by) 0x00 疑问 一直在用mysql数据库报错注入方法,但为何会报错? 百度谷歌知乎了一番,发现大家都是把官网的结论发一下截 ...
- 解决:MySQL 报错:1045 - Access denied for user 'root'@'localhost'(using password YES)
一.前言 今年疯狂迷上了开源,只要看到好的开源项目,就会不顾一切一股脑扎进去研究,五一期间发现一个很好的关于众筹的开源项目,但不巧,这个项目竟然是 PHP 写的,没学过 PHP,自然对这个开源项目毫无 ...
- 开启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 ...
- InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]'
在新建asp.net core 应用后, 添加了自定义的ApplicationDbContext 和ApplicationUser ,并添加了Identity认证后, 会出现 InvalidOpera ...
随机推荐
- docker mysql 导入导出数据
导出数据 1.导出mysql单张表结构和数据: docker exec -it my-mysql mysqldump dbname -uroot -p123456 --tables tname > ...
- centos 7安装golang1.10
一.安装&配置 官方下载包(一般需要梯子) https://golang.org/dl/ wget https://dl.google.com/go/go1.10.linux-amd64.ta ...
- 这是一份很有诚意的2017 Google I/O大会的汇总 & 解析
前言 在刚过去的凌晨(北京时间 5月18日 1.00-3.00),一年一度的2017年Google I/O大会在美国谷歌山景城海岸线圆形剧场如期举行 Google I/O 大会:Innovation ...
- Python递归函数和二分查找算法
递归函数:在一个函数里在调用这个函数本身. 递归的最大深度:998 正如你们刚刚看到的,递归函数如果不受到外力的阻止会一直执行下去.但是我们之前已经说过关于函数调用的问题,每一次函数调用都会产生一个属 ...
- 一些yuv视频下载地址
因为测试需要下载一些yuv视频地址,现存一个可以下载yuv视频的地址以备后用 http://trace.eas.asu.edu/yuv/index.html ftp://ftp.ldv.e-techn ...
- C# 将 WebService 封装成动态库
C# 将 WebService 封装成动态库 服务与服务之间的远程调用,经常会通过Web Service来实现,Web Service是支持跨语言调用的,可以是java调用c++或c#调用java等, ...
- Delphi图像处理 -- 颜色矩阵变换
转载自阿发伯:http://blog.csdn.net/maozefa/article/details/8316430 阅读提示: <Delphi图像处理>系列以效率为侧重点,一般 ...
- OpenGL中FBO的概念及其应用 [转]
http://www.cppblog.com/kongque/archive/2010/08/26/124754.html FBO一个最常见的应用就是:渲染到纹理(render to texture) ...
- intellij idea 提示找不到default activivty
更换环境之后 ,intellij idea 提示找不到默认的activity. 而查看源代码. 在代码中明显已经设置了默认activity了. 后来发现.程序中有个库工程中的AndroidMe ...
- 通过jstl判断是否给value 赋值
<input type="text" name="saler.password" id="password" value=" ...