错误添加数据模型在单独的组件中时添加迁移
我刚刚设置了新项目, pegasus (我的主要Web应用程序)和 pegasusentities (我的数据库对象)。
我的 pegasus 启动代码包括以下内容。
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(
builder.Configuration.GetConnectionString(connectionString),
builder => builder.MigrationsAssembly("PegasusEntities"));
});
如果我将 pegasus 设置为我的默认项目,并尝试添加迁移,我会遇到错误。
PM> add-migration CreateDatabase
Multiple startup projects set.
Using project 'Pegasus' as the startup project.
Build started...
Build succeeded.
Your target project 'Pegasus' doesn't match your migrations assembly 'PegasusEntities'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Pegasus")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.
我不明白这个问题。这些项目以什么方式“不匹配”?为什么要我将迁移装配设置为 pegasus ?我在另一个项目中做同样的事情,而且运行良好。
有人可以解释为什么这不起作用吗?
。
尽管我在另一个项目中做同样的事情,但它可以正常运行,但我尝试将“ Pack Manager Console”中的默认项目设置为 pegasusentities 当我这样做时,我会遇到完全不同的错误。
PM> add-migration CreateDatabase
Multiple startup projects set.
Using project 'PegasusEntities' as the startup project.
Build started...
Build succeeded.
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
- The following frameworks were found:
5.0.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.16 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64
这对我没有意义。所有项目都针对net6.0
。为什么要寻找microsoft.netcore.app
的版本2?当我打开建议的链接时,我会得到一个说的页面,此版本已达到生命的终结,这意味着不再支持它。我们建议搬到支持的版本,例如7.0运行时。。
I've just setup new projects, Pegasus (my main web application) and PegasusEntities (my database objects).
My Pegasus start-up code includes the following.
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(
builder.Configuration.GetConnectionString(connectionString),
builder => builder.MigrationsAssembly("PegasusEntities"));
});
If I set Pegasus as my default project in Package Manager Console and try to add a migration, I get an error.
PM> add-migration CreateDatabase
Multiple startup projects set.
Using project 'Pegasus' as the startup project.
Build started...
Build succeeded.
Your target project 'Pegasus' doesn't match your migrations assembly 'PegasusEntities'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Pegasus")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.
I don't understand the problem. In what way do the projects "not match?" And why is it asking me to set the migrations assembly to Pegasus? I'm doing the same thing in another project and it's been working fine.
Can someone explain why this isn't working?
Update
Although I'm doing the same thing in another project and it works fine, I tried setting the default project in Package Manager Console to PegasusEntities. When I do, I get a completely different error.
PM> add-migration CreateDatabase
Multiple startup projects set.
Using project 'PegasusEntities' as the startup project.
Build started...
Build succeeded.
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
- The following frameworks were found:
5.0.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.16 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64
This makes no sense to me. All projects are targeting net6.0
. Why is it looking for version 2 of Microsoft.NETCore.App
? When I open the suggested link, I get a page that says This release has reached end of life, meaning it is no longer supported. We recommend moving to a supported release, such as 7.0 Runtime..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我昨天只有同样的问题。
错误消息是非常误导的,即使不仅是不正确的话。
修复程序是将您的调试启动项目设置为实例化DBContext的项目,同时将项目与包装管理器控制台中选择的实体保持项目。
I had this same issue only yesterday.
The error message is very misleading, if not just plain incorrect.
The fix is to set your debug start up project to the one that instantiates the DbContext whilst keeping the project with the entities selected in the package manager console.