zoukankan      html  css  js  c++  java
  • 执行Add-Migration Initial报错

    执行Add-Migration Initial的时候,报错如下:

    Your target project 'XX.XXX.Web' doesn't match your migrations assembly 'XX.XXX.DataBase'. 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("XX.XXX.Web")). 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.

    解决办法:

    在Startup.cs文件里面

     public void ConfigureServices(IServiceCollection services)
            {
                services.AddControllers();
                //第一种方法
                //services.AddDbContext<TPLMSDbContext>(Options => Options.UseSqlServer(Configuration.GetConnectionString("TPLMSDbContext")));
                //第二种方法 services.AddDbContext<TPLMSDbContext>(options=>options.UseSqlServer("server=.\sqlexpress;database=XXX;uid=sa;pwd=*****", b => b.MigrationsAssembly("XX.XXX.Web")));
                services.AddMvc();                                 
            }

    使用第二种方法

    然后在执行:Add-Migration Initial

  • 相关阅读:
    ASP.NET简单登录注册实例
    ViewState 视图状态对象实例
    重定向redirect与跳转forward区别
    request请求对象实例
    Page_Load 事件
    JQuery增删改查
    winfrom增删改查
    SQLHelper类
    html弹出div弹窗
    react diff算法
  • 原文地址:https://www.cnblogs.com/ahao214/p/13945782.html
Copyright © 2011-2022 走看看