.net core Identity web 项目创建(一)
话不多说

身份验证类型 选择 个人账户 默认会自动创建 sql 数据库的 identity项目

创建好了 之后 查看项目


由于 我喜欢使用 mysql 这里改造成mysql 数据库
nuget Pomelo.EntityFrameworkCore.MySql 6.0 我的项目是6.0的

查看 MySQL 版本 8.0.27 SELECT VERSION()


代码
builder.Services.AddDbContext<ApplicationDbContext>(options =>
//options.UseSqlServer(connectionString)
options.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 27)))
);
修改appsettings.json 数据库连接
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'max) NULL,
CONSTRAINT `PK_AspNetRoles` PRIMARY KEY (`Id`)
)' at line 5

{
"ConnectionStrings": {
//"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-TestIdentity-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true"
"DefaultConnection": "Server=192.168.0.196;Database=TestIdentity;uid=root;pwd=123456"
},
由于 项目 默认生成的 sql 数据库迁移文件 这里 用 mysql 直接生成 会报错

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'max) NULL,
CONSTRAINT `PK_AspNetRoles` PRIMARY KEY (`Id`)
)' at line 5

这里需要重新生成 mysql迁移文件
add-Migration init -context ApplicationDbContext
重新生成 mysql 迁移文件

update-database 之后没毛病
发现mysql 数据库生成成功

浙公网安备 33010602011771号