若是涉及多個項目,注意保持DbContext所在項目和啓動項目關於數據庫的包引用版本一致
注意設置不一樣的DbContext遷移文件目錄不一樣
1.Enable-migrationsshell
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-databasespa
EntityFrameworkCore\update-database -Context TestDbContext1
存在多個DbContext的時候不指名Context的報錯內容code
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 DbContexthtm