升级到ASP.NET Core 2.0后,似乎无法再创建迁移。升级到ASP.NET Core 2.0后无法创建迁移
我越来越
"An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: One or more errors occurred. (Cannot open database "..." requested by the login. The login failed. Login failed for user '...'"
和
"Unable to create an object of type 'MyContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time."
我以前运行是$ dotnet ef migrations add InitialCreate --startup-project "..\Web"
(从与的DbContext项目/文件夹)的命令。
连接字符串:"Server=(localdb)\\mssqllocaldb;Database=database;Trusted_Connection=True;MultipleActiveResultSets=true"
这是我的Program.cs
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
问题可能不在Program.cs中。这可能是使用指令在Configure方法的末尾加载种子数据: DbInitializer.Initialize(context); 如果您有该指令,请对其进行注释: //DbInitializer.Initialize(context); 然后运行迁移说明进行测试。如果问题出现,请继续DbInitializer.cs类。 –
是另一个类库项目中的MyContext类吗? – Orhun
这里同样的问题,上下文在其他库中。如果id在上下文中添加一个参数less consturctor,则migrations正在工作,但是会出现相同的错误:(在'Program'类中调用方法'BuildWebHost'时发生错误,继续执行没有应用程序服务提供程序错误:未设置对象引用到一个对象的实例。 ) – iBoonZ