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.

参考资料

Entity Framework Core tools reference - Package Manager Console in Visual Studio
Entity Framework - Multiple DbContext
Code First Migration in Multiple DbContext


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM