【问题标题】:Migrations in netcore 3.1 not working in a different project using MigrationsAssemblynetcore 3.1 中的迁移不能在使用 MigrationsAssembly 的不同项目中工作
【发布时间】:2021-08-26 22:57:56
【问题描述】:

我正在尝试在另一个项目中添加迁移,而我在这里确实是白发苍苍,尝试到处找到不同的解决方案,但都没有奏效,我只是不明白为什么不起作用。

我在 Startup.cs 中有这个

 services.AddDbContext<ApplicationDbContext>(
            c => c.UseSqlServer(_config.GetConnectionString("ApplicationDbContext"), 
            opt => opt.MigrationsAssembly("DatabaseContext.Migrations")));

我确实检查了thisthisthis,我想还有一些其他的,我不知道出了什么问题。

对于我的解决方案结构如下:

Shop (former empty solution)
1. DatabaseSchema (folder with empty spaces)
DatabaseContext (project with the migrations folder inside)
..
bunch of other stuff
..
ShopApi (here I have that code above in Startup.cs)

我试过了:

dotnet ef 迁移添加 ExampleMigration -s ../ShopAPI dotnet ef 迁移脚本 --project DatabaseContext --startup-project ../ShopAPI

它只是说没有找到项目,我不明白路径有什么问题,我向上一个文件夹,项目就在那里。由于它变得非常烦人并且我很紧张,我尝试了所有路径组合,但仍然没有找到任何东西。

路径是这样的:

Shop (Solution) -> 1. DatabaseSchema (Folder) -> DatabaseContext/Migrations
                -> ShopAPI (is where I have my Startup.cs)

这里有什么不明白的地方?

【问题讨论】:

    标签: .net-core asp.net-core-3.1


    【解决方案1】:

    是的,我解决了这个问题 我用这个命令代替

    Add-Migration Subcategory_Entity_Added -StartupProject ShopAPI
    

    在包管理器控制台上,我设置了迁移父项目。

    我删除了 MigrationsAssembly 部分,因为上面的命令给出了不同的错误:

    Could not load file or assembly 'DatabaseContext.Migrations, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
    

    所以我猜它会将路径读取为..因为'.'而寻找特定文件,我不确定,我删除了所有内容并尝试了它。

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2016-02-21
      • 2019-02-19
      • 2021-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多