简体   繁体   中英

ASP.NET Core RC2 Identity Database Schema Migrations

In the new ASP.NET Core RC2 template (With no database available at the back-end), when I try to register a user it throws the following error for adding Migrations.

在此处输入图片说明

While in the past, it use to generate the database for us without adding initial migration when we run the application. Is there a way to create the database in ASP.NET Core RC2 without Initial Migration?

For testing scenario you can use context.Database.EnsureCreatedAsync() somewhere during startup. Ensure you are using this pattern (for now) and not inject it directly in configure, to avoid issues during startup.

For future reference the code section copied from the MusicStore example application.

using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
    var db = serviceScope.ServiceProvider.GetService<MusicStoreContext>();

    if (await db.Database.EnsureCreatedAsync())
    {
        await InsertTestData(serviceProvider);
        if (createUsers)
        {
            await CreateAdminUser(serviceProvider);
        }
    }
}

because at this point, there is no scope yet. If you later want to apply the migrations you can use context.Database.AsRelational().ApplyMigrations() ( GitHub issue )

我猜唯一的替代方法是手动创建数据库,也许使用Sql Server Object Explorer ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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