EF Core Migration error: “Unable to create an object of type 'ApplicationContext'”

橙三吉。 提交于 2019-12-12 11:26:26

问题


I'm trying to do the migration with EF Core but I get an error - how can I fix this error?

PM> add-migration ini

Unable to create an object of type 'ApplicationContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.


回答1:


This will also happen if you have multiple start-up projects - when migrating, just select one (in VS right click Solution and Set StartUp Projects...)




回答2:


1.Modify your code in ConfigureService with :

options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),

        x => x.MigrationsAssembly("WebApplication")));
  1. In command line which includes WebApplication.csproj:

dotnet ef migrations add Init



来源:https://stackoverflow.com/questions/51343295/ef-core-migration-error-unable-to-create-an-object-of-type-applicationcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!