简体   繁体   English

无法在ASP.NET Core 2.0中创建迁移

[英]Can't create migration in asp.net core 2.0

I am trying to create Identity migration is ASP.NET Core 2.0 and getting error. 我正在尝试创建身份迁移是ASP.NET Core 2.0,并且出现错误。

System.Data.SqlClient.SqlException (0x80131904): Cannot open database "MarketIdentity" requested by the login. System.Data.SqlClient.SqlException(0x80131904):无法打开登录请求的数据库“ MarketIdentity”。 The login failed. 登录失败。

Appsettings.json Appsettings.json

"MarketIdentity": {
  "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=MarketIdentity;Trusted_Connection=True;MultipleActiveResultSets=true"
}

startup.cs startup.cs

public void ConfigureServices(IServiceCollection services)
    {
        //services.Configure<AppSettings>(Configuration.GetSection("Data:Market"));

        services.AddMvc();

        //app database
        services.AddDbContext<EfDbContext>(
            options => options.UseSqlServer(Configuration["Data:Market:ConnectionString"],
            b => b.MigrationsAssembly("Market")));

        //identity database
        services.AddDbContext<AppIdentityDbContext>(
            options => options.UseSqlServer(Configuration["Data:MarketIdentity:ConnectionString"],
            b => b.MigrationsAssembly("Market")));

        services.AddIdentity<IdentityUser, IdentityRole>(options => {
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequireUppercase = false;
            options.Password.RequireLowercase = false;
            options.Password.RequireDigit = false;
        })
            .AddEntityFrameworkStores<AppIdentityDbContext>();
    }

try this 尝试这个

"ConnectionStrings": {
    "MarkIdentity": "Server=(localdb)\\mssqllocaldb;Database=MarketIdentity;Trusted_Connection=True;MultipleActiveResultSets=true"
}

services.AddDbContext<EfDbContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("MarkIdentity")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM