【问题标题】:Asp.Net Core How to Configure Migrations type to assemblyAsp.Net Core 如何将迁移类型配置为程序集
【发布时间】:2020-09-11 14:22:16
【问题描述】:

大家好,我的名字是 Taniguchi,我学习 asp.net core,我设法创建了一个迁移,但是当我使用 Update-Database 命令时,显示以下错误:“

指定“-Verbose”标志以查看应用于目标数据库的 SQL 语句。 在程序集“WebApplication1”中找不到迁移配置类型。 (在 Visual Studio 中,您可以使用包管理器控制台中的 Enable-Migrations 命令添加迁移配置)。

我的数据库:

 public class MimicContext : DbContext
{
    public MimicContext(DbContextOptions<MimicContext> options) : base(options)
    {

    }

    public DbSet<Palavra> Palavras { get; set; }
}

我的创业:

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {

        services.AddDbContext<MimicContext>(opt =>
        {
            opt.UseSqlite("Data Source=Database\\Mimic.db");
        });

        services.AddMvc(options => options.EnableEndpointRouting = false);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

       

        app.UseMvc();
    }
}

如何配置迁移到程序集?

【问题讨论】:

    标签: c# asp.net-web-api database-migration


    【解决方案1】:

    您是否在项目中启用了迁移?如果您没有使用 Enable-Migrations。我认为这可能是问题所在。

    【讨论】:

    • 我使用了此命令,但显示以下错误:在程序集“WebApplication1”中未找到上下文类型。但我创建的上下文是 MimicContext ?
    • 然后尝试完整的命令:Enable-Migrations -ProjectName MyContextProjectNameHere -StartUpProjectName MyStartUpProjectNameHere
    • 在 MyContextProjectNameHere 中输入上下文名称,在 MyStartUpProjectNameHere 中输入项目名称?
    【解决方案2】:

    在 PMC 中运行 update 命令之前,请先启用它。更多详情请查看此链接here

    【讨论】:

    • While‌ ‌this‌ ‌link‌ ‌may‌ ‌answer‌ ‌the‌ ‌question,‌ ‌it‌ ‌is‌ ‌better‌ ‌to‌ ‌include‌ ‌the‌ ‌essential‌ ‌parts‌ ‌of‌ ‌the‌ ‌ answer‌ ‌here‌ ‌and‌ ‌provide‌ ‌the‌ ‌link‌ ‌for‌ ‌reference.‌ ‌Link-only‌ ‌answers‌ ‌can‌ ‌become‌ ‌invalid‌ ‌if‌ ‌the‌ ‌ linked‌ ‌page‌ ‌变化。
    【解决方案3】:

    小错误,但经过一天多的痛苦努力,对我来说是一个很好的学习。我希望这对其他人也是一个很好的学习。

    我添加了两个 NuGet 包:EntityFramework 和 Microsoft.EntityFrameworkCore,这是我的错误。

    只需为 Microsoft.EntityFrameworkCore 添加 NuGet 包即可完成所有必需的工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 2019-10-26
      • 2017-06-30
      • 1970-01-01
      • 2022-01-08
      相关资源
      最近更新 更多