100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > core identity mysql_Asp.Net Core Identity 4 改成 MySql/MariaDB

core identity mysql_Asp.Net Core Identity 4 改成 MySql/MariaDB

时间:2024-02-24 04:47:56

相关推荐

core identity mysql_Asp.Net Core Identity 4 改成 MySql/MariaDB

一、在NuGet安装以下包1、 Pomelo.EntityFrameworkCore.MySql

2、Microsoft.EntityFrameworkCore.Tools

3、Microsoft.AspNetCore.Identity

4、Microsoft.AspNetCore.Identity.EntityFrameworkCore

5、Microsoft.AspNetCore.Identity.UI

二、Data目录下新建Identity的数据库上下文(DbContext)public class DataContext : IdentityDbContext

{

public DataContext(DbContextOptions options)

: base(options)

{

}

protected override void OnModelCreating(ModelBuilder builder)

{

base.OnModelCreating(builder);

}

}

三、appsettings.json配置数据库连接字符串

四、在Startup.cs中注册数据库上下文服务和对identity进行相关设置services.AddDbContext(options =>

{

options.UseMySql(Configuration.GetConnectionString("DefaultConnection"));

});

services.AddDefaultIdentity()

.AddEntityFrameworkStores()

.AddDefaultTokenProviders();

五、对每个DbContext进行一次迁移。add-migration XXX

update-database

结束。

注意生成的SQL可能会遇到长度限制问题导致update-database失败,

这时候需要手动改一下系统生成的Migration,把Max Length = 256通通改为255,utf8mb4改为utf8。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。