添加第一个数据库迁移的asp.net核心问题

时间:2022-07-12 11:59:45

I am using new asp.net core and have my classes and db context in a sep dll I have added the code acording to the docs.

我正在使用新的asp.net核心,并将我的类和db上下文添加到一个sep dll中。

public IConfigurationRoot Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
        services.AddDbContext<solitudeDContext>(options => 


 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection") 
  ,b=>b.MigrationsAssembly("solitudedcore")));          
    }

But I am still getting the following error when I run the following command

但是当我运行以下命令时,仍然会得到以下错误

dotnet ef migrations add firstdb

dotnet ef迁移添加了firstdb

Your target project 'solitudeeccore' doesn't match your migrations assembly 'solitudedcore'. 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("solitudeeccore")). 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.

您的目标项目“solitudeeccore”与您的迁移程序集“solitudedcore”不匹配。要么更改目标项目,要么更改迁移程序集。通过使用dbcontext toptionsbuilder更改迁移程序集。如选择。UseSqlServer(连接,b = > b.MigrationsAssembly(“solitudeeccore”))。默认情况下,迁移程序集是包含DbContext的程序集。通过使用包管理器控制台的默认项目下拉列表或从包含迁移项目的目录执行“dotnet ef”,将目标项目更改为migrations项目。

I have changed the drop down to the project and added the b=>b.MigrationsAssembly("solitudedcore") as directed here on EF cores github https://github.com/aspnet/EntityFramework/issues/7869

我已经将下拉改为项目,并添加了b=>b.MigrationsAssembly(“solitudedcore”),如这里针对EF核心github的github (https://github.com/aspnet/EntityFramework/issues/7869)

I also included my project includes for your reference.

我也包括了我的项目包括供你参考。

<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
  <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
  <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
  <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
  <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
  <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />

And my appsettings files as follows

我的appsettings文件如下

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },

  "ConnectionStrings": {
    "DefaultConnection": "Data Source=DESKTOP-JHIMUM4\\SQLEXPRESS2014;Initial Catalog=solitudeec;Trusted_Connection=True;MultipleActiveResultSets=true"
  }


}

Any ideas or solutions would be appreciated.

任何想法或解决方案都将受到欢迎。

Please find my project layout here

请在这里找到我的项目布局

https://imgur.com/a/oSvr4

https://imgur.com/a/oSvr4

Edit 1

编辑1

The below person was indeed correct it is the spelling of the dll but also you need to target the project which hosts your dll not the actual dll itself.

下面的人确实是正确的,这是dll的拼写,但是你也需要针对你的dll,而不是实际的dll本身。

To create the migration in the cmd prompt call

在cmd提示调用中创建迁移

dotnet ef migrations add firstdb

dotnet ef迁移添加了firstdb

and to push your changes out simply call

要将您的更改推出,只需调用

dotnet ef database update -e Production

dotnet ef数据库更新-e产品

1 个解决方案

#1


2  

There is spelling mistake in migration assembly name.

迁移程序集名称中存在拼写错误。

Your target project 'solitudeeccore' doesn't match your migrations assembly 'solitudedcore'.

目标项目“solitudeeccore”与迁移程序集“solitudedcore”不匹配。

#1


2  

There is spelling mistake in migration assembly name.

迁移程序集名称中存在拼写错误。

Your target project 'solitudeeccore' doesn't match your migrations assembly 'solitudedcore'.

目标项目“solitudeeccore”与迁移程序集“solitudedcore”不匹配。