1、安装ef tools
首先确保本地netcore sdk安装完毕,如下是卸载tool、安装指定版本tool、更新到指定版本的tool 的命令:
dotnet tool uninstall --global dotnet-ef
dotnet tool install --global dotnet-ef --version 5.0.0
dotnet tool update --global dotnet-ef --version 5.0.5
2、在目标项目安装Microsoft.EntityFrameworkCore.Tools nuget包
3、定位到指定项目解决方案下(..csproj文件不是sln) 让cmd工作目录定位到当前目录
4、迁移dbcontext
dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
5、更新到数据库
dotnet ef database update --context PersistedGrantDbContext
6、删除指定上下文对应的数据库(慎用)
dotnet ef database drop --context PersistedGrantDbContext
7、为迁移创建sql脚本
dotnet ef migrations script 0 20220510070558_InitialIdentityServerPersistedGrantDbMigration --context PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb/1.sql
注意:指令中的script 0 代表为20220510070558_InitialIdentityServerPersistedGrantDbMigration创建迁移脚本,如果不加0,如下:
dotnet ef migrations script 20220510070558_InitialIdentityServerPersistedGrantDbMigration --context PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb/1.sql
则代表为20220510070558_InitialIdentityServerPersistedGrantDbMigration之后的迁移创建迁移脚本.
dotnet tool update --global dotnet-ef
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有