EF Core 多个DbContext迁移命令

如果涉及多个项目,注意保持DbContext所在项目和启动项目关于数据库的包引用版本一致
注意设置不同的DbContext迁移文件目录不同
1.Enable-migrations

EntityFrameworkCore\Enable-migrations –ContextTypeName:Namespace.TestDbContext1 –MigrationDirectory:MigrationDirectory1 
EntityFrameworkCore\Enable-migrations –ContextTypeName:Namespace.TestDbContext2 –MigrationDirectory:MigrationDirectory2 

2.Add-Migration

EntityFrameworkCore\Add-migration migration_name -Context TestDbContext1 -OutputDir MigrationDirectory1

必须指明-Context参数,参数为DbContext类名
3.update-database

EntityFrameworkCore\update-database -Context TestDbContext1
其他

存在多个DbContext的时候不指名Context的报错内容

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.
参考资料

https://www.tutorialspoint.com/entity_framework/entity_framework_multiple_dbcontext.htm
https://www.codeproject.com/tips/801628/code-first-migration-in-multiple-dbcontext
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

转载于:https://www.cnblogs.com/Lulus/p/11408263.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值