无法创建类型的对象' appContext'。使用冗长,但是
我试图进行第一次迁移,并遇到了这个错误。
我使用了:
dotnet ef migrations add initial --project AppProject.Core --verbose
错误:
Finding application service provider in assembly 'AppProject.Core'...
Finding Microsoft.Extensions.Hosting service provider...
-> No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
-> No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'AppContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'AppContext'.
我的program.cs
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
我的创业公司
services.AddDbContext<AppContext>(options =>
{
options.UseNpgsql(connection);
});
services.AddIdentity<User, IdentityRole<Guid>>()
.AddEntityFrameworkStores<SysFishingContext>()
.AddDefaultTokenProviders();
我没有得到什么问题。请有人帮我。
I tried to do my first migration and I got this error.
I used:
dotnet ef migrations add initial --project AppProject.Core --verbose
The error:
Finding application service provider in assembly 'AppProject.Core'...
Finding Microsoft.Extensions.Hosting service provider...
-> No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
-> No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'AppContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'AppContext'.
My Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
My Startup
services.AddDbContext<AppContext>(options =>
{
options.UseNpgsql(connection);
});
services.AddIdentity<User, IdentityRole<Guid>>()
.AddEntityFrameworkStores<SysFishingContext>()
.AddDefaultTokenProviders();
I don't get what is the problem. Please someone help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试指定这两个选项
- 项目
和- startup-project
-p | -project&lt; project&gt;
这是该项目
dbContext
坐在。-s | - startup-project&lt; project&gt;
这是带有依赖性注入设置的项目,通常是Web项目。
您的
迁移添加
命令可能看起来如下:Try to specify both options
--project
and--startup-project
-p|--project <PROJECT>
This is the project that
DbContext
is sitting in.-s|--startup-project <PROJECT>
This is the project with Depenedency Injection setup, usually the Web project.
Your
migrations add
command might look like below: